-
Notifications
You must be signed in to change notification settings - Fork 53.7k
[Bael-7734] Add Examples #19143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeoColman
wants to merge
15
commits into
eugenp:master
Choose a base branch
from
LeoColman:BAEL-7734
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Bael-7734] Add Examples #19143
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cbc746a
[Bael-7734] Add Examples
LeoColman f58bc16
[Bael-7734] Improve Examples
LeoColman 142f731
[Bael-7734] Add Examples
LeoColman c773d0f
[Bael-7734] Add Examples
LeoColman c35dfe5
[Bael-7734] Add Examples
LeoColman 52f44dc
[Bael-7734] Add Examples
LeoColman 3da7d39
[Bael-7734] Add Examples
LeoColman 3d00592
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Dat…
LeoColman 0fc4275
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Nam…
LeoColman 3808876
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Dat…
LeoColman a4f6fd0
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Fac…
LeoColman a464044
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Nam…
LeoColman 76ec5d6
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Nam…
LeoColman 861dc9b
Update testing-modules/testng-2/src/test/java/com/baeldung/testng/Fac…
LeoColman 1af073a
[Bael-7734] Add Examples
LeoColman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
testing-modules/testng-2/src/test/java/com/baeldung/testng/DataDrivenNameTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.baeldung.testng; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class DataDrivenNameTest { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(DataDrivenNameTest.class); | ||
| private String testName; | ||
|
|
||
| @BeforeMethod | ||
| public void capture(Method method, Object[] params) { | ||
| String testName = method.getName() + Arrays.toString(params); | ||
LeoColman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.testName = testName; | ||
| } | ||
|
|
||
| @Test(dataProvider = "numbers") | ||
| public void givenInputParameters_whenFetchingTestName_thenShouldReturnCorrectTestName(int input, int expected) { | ||
| logger.info("Executing scenario from {}", testName); | ||
| Assert.assertListContainsObject(List.of("givenInputParameters_whenFetchingTestName_thenShouldReturnCorrectTestName[2, 4]", | ||
| "givenInputParameters_whenFetchingTestName_thenShouldReturnCorrectTestName[3, 9]"), testName, "Test name is not as expected"); | ||
| } | ||
|
|
||
| @DataProvider | ||
| public Object[][] numbers() { | ||
| return new Object[][] { { 2, 4 }, { 3, 9 } }; | ||
| } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
testing-modules/testng-2/src/test/java/com/baeldung/testng/FactoryNameTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.baeldung.testng; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.ITestResult; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Factory; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class FactoryNameTest { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(FactoryNameTest.class); | ||
| private final String instanceLabel; | ||
|
|
||
| public FactoryNameTest(String instanceLabel) { | ||
| this.instanceLabel = instanceLabel; | ||
| } | ||
|
|
||
| @Factory | ||
| public static Object[] build() { | ||
| return new Object[] { new FactoryNameTest("fast-path"), new FactoryNameTest("slow-path") }; | ||
theangrydev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @BeforeMethod | ||
| public void capture(Method method, ITestResult result) { | ||
| String fullName = method.getName() + "[" + instanceLabel + "]"; | ||
| result.setAttribute("displayName", fullName); | ||
| } | ||
|
|
||
| @Test | ||
| public void givenTestNameSetup_whenTestNameIsRequested_thenShouldReturnTestName() { | ||
| logger.info("Executing scenario {}", instanceLabel); | ||
| Assert.assertListContainsObject(List.of("fast-path", "slow-path"), instanceLabel, "instance label is not as expected"); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
testing-modules/testng-2/src/test/java/com/baeldung/testng/NameByReflectionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.baeldung.testng; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| public class NameByReflectionTest { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(NameByReflectionTest.class); | ||
| private String testName; | ||
|
|
||
| @BeforeMethod | ||
| public void capture(Method method) { | ||
| String testName = method.getName(); | ||
| this.testName = testName; | ||
| } | ||
|
|
||
| @Test | ||
| public void givenTestNameSetup_whenTestNameIsRequested_thenShouldReturnTestName() { | ||
| logger.info("Executing scenario {}", testName); | ||
| Assert.assertEquals(testName, "givenTestNameSetup_whenTestNameIsRequested_thenShouldReturnTestName"); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
testing-modules/testng-2/src/test/java/com/baeldung/testng/NameByResultTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.baeldung.testng; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.ITestResult; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class NameByResultTest { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(NameByResultTest.class); | ||
| private String testName; | ||
|
|
||
| @BeforeMethod | ||
| public void capture(ITestResult result) { | ||
| String testName = result.getMethod().getMethodName(); | ||
| this.testName = testName; | ||
| } | ||
|
|
||
| @Test | ||
| public void givenTestNameSetup_whenTestNameIsRequested_thenShouldReturnTestName() { | ||
| logger.info("Executing scenario {}", testName); | ||
| Assert.assertEquals(testName, "givenTestNameSetup_whenTestNameIsRequested_thenShouldReturnTestName"); | ||
| } | ||
LeoColman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
25 changes: 25 additions & 0 deletions
25
testing-modules/testng-2/src/test/java/com/baeldung/testng/NameByXmlSuiteTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.baeldung.testng; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.ITestContext; | ||
| import org.testng.annotations.BeforeTest; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class NameByXmlSuiteTest { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(NameByXmlSuiteTest.class); | ||
| private String iTestContextSuiteName; | ||
|
|
||
| @BeforeTest | ||
| public void fetchSuiteNameFromITestContext(ITestContext ctx) { | ||
| iTestContextSuiteName = ctx.getName(); | ||
| } | ||
|
|
||
| @Test | ||
| public void givenTestContextSetup_whenRequestingSuiteName_thenShouldReturnSuiteName() { | ||
| logger.info("Executing scenario from {}", iTestContextSuiteName); | ||
| Assert.assertEquals(iTestContextSuiteName, "All Tests"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.