forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline test parameter visibility in config method
Closes testng-team#2255
- Loading branch information
1 parent
78a3ce7
commit d480811
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,17 @@ | ||
package test.dataprovider.issue2255; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.testng.TestNG; | ||
import org.testng.annotations.Test; | ||
import test.SimpleBaseTest; | ||
|
||
public class IssueTest extends SimpleBaseTest { | ||
|
||
@Test(description = "GITHUB-2255") | ||
public void runTest() { | ||
TestNG testNG = create(SampleTestCase.class); | ||
testNG.setVerbose(2); | ||
testNG.run(); | ||
assertThat(SampleTestCase.data).containsExactly(100, 200); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/test/dataprovider/issue2255/SampleTestCase.java
This file contains 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,40 @@ | ||
package test.dataprovider.issue2255; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.testng.ITestResult; | ||
import org.testng.Reporter; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import test.SimpleBaseTest; | ||
|
||
public class SampleTestCase extends SimpleBaseTest { | ||
|
||
static final List<Integer> data = new ArrayList<>(); | ||
private static final AtomicInteger counter = new AtomicInteger(0); | ||
|
||
@BeforeMethod | ||
public void beforeMethod(ITestResult result) { | ||
Object[] parameters = result.getParameters(); | ||
if (parameters == null || parameters.length == 0) { | ||
throw new IllegalStateException("parameters aren't visible"); | ||
} | ||
data.add((Integer) parameters[0]); | ||
} | ||
|
||
@Test(dataProvider = "dp") | ||
public void testMethod(int i) { | ||
int index = counter.getAndIncrement(); | ||
assertThat(i).isEqualTo(data.get(index)); | ||
Integer value = (Integer) Reporter.getCurrentTestResult().getParameters()[0]; | ||
assertThat(value).isEqualTo(data.get(index)); | ||
} | ||
|
||
@DataProvider(name = "dp") | ||
public Object[][] getData() { | ||
return new Object[][] {{100}, {200}}; | ||
} | ||
} |
This file contains 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