-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling invocation-number to xml for DataProvider + Factory (#2516)
Closes #2517
- Loading branch information
1 parent
5182035
commit 5cffe02
Showing
8 changed files
with
109 additions
and
6 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
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
28 changes: 28 additions & 0 deletions
28
.../test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterSample.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,28 @@ | ||
package test.failedreporter.issue2517; | ||
|
||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class DataProviderWithFactoryFailedReporterSample { | ||
private Integer data; | ||
|
||
@Factory(dataProvider = "dp") | ||
public DataProviderWithFactoryFailedReporterSample(Integer data) { | ||
this.data = data; | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] dp() { | ||
return new Object[][]{ | ||
new Object[]{0}, new Object[]{1}, new Object[]{2}, | ||
}; | ||
} | ||
|
||
@Test | ||
public void f1() { | ||
if (data == 1) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...rc/test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterTest.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,55 @@ | ||
package test.failedreporter.issue2517; | ||
|
||
import org.testng.Assert; | ||
import org.testng.TestNG; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.testng.collections.Lists; | ||
import test.SimpleBaseTest; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
public class DataProviderWithFactoryFailedReporterTest extends SimpleBaseTest { | ||
private File mTempDirectory; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
mTempDirectory = createDirInTempDir("testng-tmp-" + System.currentTimeMillis() % 1000); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() { | ||
deleteDir(mTempDirectory); | ||
} | ||
|
||
@Test | ||
public void failedMethodWithDataProviderAndFactoryShouldHaveInvocationNumbers() { | ||
testFailedReporter( | ||
new String[]{"f1"}, | ||
"<include name=\"%s\" invocation-numbers=\"1\"/>", | ||
DataProviderWithFactoryFailedReporterSample.class); | ||
} | ||
|
||
private void testFailedReporter(String[] expectedMethods, String expectedLine, Class<?>... cls) { | ||
triggerTest(cls); | ||
runAssertions(mTempDirectory, expectedMethods, expectedLine, 1); | ||
} | ||
|
||
private void triggerTest(Class<?>... cls) { | ||
TestNG tng = create(mTempDirectory.toPath(), cls); | ||
tng.setUseDefaultListeners(true); | ||
tng.run(); | ||
} | ||
|
||
private static void runAssertions( | ||
File outputDir, String[] expectedMethods, String expectedLine, int expected) { | ||
File failed = new File(outputDir, "testng-failed.xml"); | ||
for (String s : expectedMethods) { | ||
List<String> resultLines = Lists.newArrayList(); | ||
grep(failed, String.format(expectedLine, s), resultLines); | ||
Assert.assertEquals(resultLines.size(), expected); | ||
} | ||
} | ||
} |
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