Added tests for the new failed reporter feature.
diff --git a/src/org/testng/internal/Invoker.java b/src/org/testng/internal/Invoker.java
index cffa316..dfa9c7b 100644
--- a/src/org/testng/internal/Invoker.java
+++ b/src/org/testng/internal/Invoker.java
@@ -609,6 +609,10 @@
// If this method has a data provider and just failed, memorize the number
// at which it failed.
+ // Note: we're not exactly testing that this method has a data provider, just
+ // that it has parameters, so might have to revisit this if bugs get reported
+ // for the case where this method has parameters that don't come from a data
+ // provider
if (testResult.getThrowable() != null && parameterValues.length > 0) {
tm.addFailedInvocationNumber(tm.getCurrentInvocationCount());
}
diff --git a/test/src/test/failedreporter/FailedReporter2SampleTest.java b/test/src/test/failedreporter/FailedReporter2SampleTest.java
new file mode 100644
index 0000000..25f1a47
--- /dev/null
+++ b/test/src/test/failedreporter/FailedReporter2SampleTest.java
@@ -0,0 +1,20 @@
+package test.failedreporter;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class FailedReporter2SampleTest {
+ @DataProvider
+ public Object[][] dp() {
+ return new Object[][] {
+ new Object[] { 0 },
+ new Object[] { 1 },
+ new Object[] { 2 },
+ };
+ }
+
+ @Test(dataProvider = "dp")
+ public void f1(Integer ip) {
+ if (ip == 1) throw new RuntimeException();
+ }
+}
diff --git a/test/src/test/failedreporter/FailedReporterTest.java b/test/src/test/failedreporter/FailedReporterTest.java
index 6e827bb..55f1172 100644
--- a/test/src/test/failedreporter/FailedReporterTest.java
+++ b/test/src/test/failedreporter/FailedReporterTest.java
@@ -31,17 +31,26 @@
@Test
public void failedAndSkippedMethodsShouldBeIncluded() throws IOException {
+ testFailedReporter(FailedReporterSampleTest.class, new String[] { "f1", "f2" },
+ "<include name=\"%s\"" + "\"/>"); }
+
+ @Test
+ public void failedMethodWithDataProviderShouldHaveInvocationNumbers() throws IOException {
+ testFailedReporter(FailedReporter2SampleTest.class, new String[] { "f1" },
+ "<include invocationNumbers=\"1\" name=\"%s\"" + "\"/>");
+ }
+
+ private void testFailedReporter(Class<?> cls, String[] expectedMethods, String expectedLine) {
TestNG tng = new TestNG();
tng.setVerbose(0);
- tng.setTestClasses(new Class[] { FailedReporterSampleTest.class });
+ tng.setTestClasses(new Class[] { cls });
tng.setOutputDirectory(mTempDirectory.getAbsolutePath());
tng.run();
- String[] expected = new String[] { "f1", "f2" };
File failed = new File(mTempDirectory, "testng-failed.xml");
- for (String s : expected) {
+ for (String s : expectedMethods) {
List<String> resultLines = Lists.newArrayList();
- BaseTest.grep(failed, "<include name=\"" + s + "\"/>", resultLines);
+ grep(failed, expectedLine.format(s), resultLines);
Assert.assertEquals(1, resultLines.size());
}