Permalink
Browse files

Fixed: testng-failed.xml now includes skipped tests

  • Loading branch information...
1 parent bfb18c2 commit d1bcd1920bbabe45f46175d832e8a1a87c693652 cbeust committed Apr 27, 2009
View
@@ -1,5 +1,6 @@
Current:
+Fixed: testng-failed.xml now includes skipped tests
Added: @Test(expectedExceptionsMessageRegExp = ".*foo.*"
Added: @DataProvider(parallel=true)
Fixed: TestNG couldn't find Groovy files (Haw-Bin)
@@ -104,19 +104,25 @@ private void generateXmlTest(ISuite suite,
// Get the transitive closure of all the failed methods and the methods
// they depend on
- Collection<ITestResult> tests = failedTests.isEmpty() ? skippedTests : failedTests;
- for (ITestResult failedTest : tests) {
- ITestNGMethod current = failedTest.getMethod();
- if (current.isTest()) {
- methodsToReRun.put(current, current);
- ITestNGMethod method = failedTest.getMethod();
- // Don't count configuration methods
- if (method.isTest()) {
- List<ITestNGMethod> methodsDependedUpon = MethodHelper.getMethodsDependedUpon(method, context.getAllTestMethods());
-
- for (ITestNGMethod m : methodsDependedUpon) {
- if (m.isTest()) {
- methodsToReRun.put(m, m);
+ Collection[] allTests = new Collection[] {
+ failedTests, skippedTests
+ };
+
+ for (Collection<ITestResult> tests : allTests) {
+ for (ITestResult failedTest : tests) {
+ ITestNGMethod current = failedTest.getMethod();
+ if (current.isTest()) {
+ methodsToReRun.put(current, current);
+ ITestNGMethod method = failedTest.getMethod();
+ // Don't count configuration methods
+ if (method.isTest()) {
+ List<ITestNGMethod> methodsDependedUpon =
+ MethodHelper.getMethodsDependedUpon(method, context.getAllTestMethods());
+
+ for (ITestNGMethod m : methodsDependedUpon) {
+ if (m.isTest()) {
+ methodsToReRun.put(m, m);
+ }
}
}
}
@@ -21,6 +21,11 @@
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -29,6 +34,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
/**
* Base class for tests
@@ -366,6 +372,58 @@ protected void dumpResults(String name, Map<String, List<ITestResult>> tests) {
}
}
+ /**
+ *
+ * @param fileName The filename to parse
+ * @param regexp The regular expression
+ * @param resultLines An out parameter that will contain all the lines
+ * that matched the regexp
+ * @return A List<Integer> containing the lines of all the matches
+ *
+ * Note that the size() of the returned valuewill always be equal to
+ * result.size() at the end of this function.
+ */
+ public static List<Integer> grep(File fileName, String regexp, List<String> resultLines) {
+ List<Integer> resultLineNumbers = new ArrayList<Integer>();
+ BufferedReader fr = null;
+ try {
+ fr = new BufferedReader(new FileReader(fileName));
+ String line = fr.readLine();
+ int currentLine = 0;
+ Pattern p = Pattern.compile(".*" + regexp + ".*");
+
+ while(null != line) {
+ // ppp("COMPARING " + p + " TO @@@" + line + "@@@");
+ if(p.matcher(line).matches()) {
+ resultLines.add(line);
+ resultLineNumbers.add(currentLine);
+ }
+
+ line = fr.readLine();
+ currentLine++;
+ }
+ }
+ catch(FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ catch(IOException e) {
+ e.printStackTrace();
+ }
+ finally {
+ if(null != fr) {
+ try {
+ fr.close();
+ }
+ catch(IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ return resultLineNumbers;
+
+ }
+
private static class InternalTestRunnerFactory implements ITestRunnerFactory {
private final BaseTest m_baseTest;
@@ -387,6 +445,27 @@ public TestRunner newTestRunner(ISuite suite, XmlTest test) {
}
}
+ /**
+ * Deletes all files and subdirectories under dir.
+
+ * @return true if all deletions were successful.
+ * If a deletion fails, the method stops attempting to delete and returns false.
+ */
+ public static boolean deleteDir(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i=0; i<children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+
protected void runTest(String cls, String[] passed, String[] failed, String[] skipped) {
addClass(cls);
run();
@@ -6,73 +6,18 @@
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.Type;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.regex.Pattern;
import org.testng.AnnotationConverter;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class AnnotationConverterTest {
-
- /**
- *
- * @param fileName The filename to parse
- * @param regexp The regular expression
- * @param resultLines An out parameter that will contain all the lines
- * that matched the regexp
- * @return A List<Integer> containing the lines of all the matches
- *
- * Note that the size() of the returned valuewill always be equal to
- * result.size() at the end of this function.
- */
- static List<Integer> grep(File fileName, String regexp, List<String> resultLines) {
- List<Integer> resultLineNumbers = new ArrayList<Integer>();
- BufferedReader fr = null;
- try {
- fr = new BufferedReader(new FileReader(fileName));
- String line = fr.readLine();
- int currentLine = 0;
- Pattern p = Pattern.compile(".*" + regexp + ".*");
-
- while(null != line) {
-// ppp("COMPARING " + p + " TO @@@" + line + "@@@");
- if(p.matcher(line).matches()) {
- resultLines.add(line);
- resultLineNumbers.add(currentLine);
- }
-
- line = fr.readLine();
- currentLine++;
- }
- }
- catch(FileNotFoundException e) {
- e.printStackTrace();
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- finally {
- if(null != fr) {
- try {
- fr.close();
- }
- catch(IOException ex) {
- ex.printStackTrace();
- }
- }
- }
+import test.BaseTest;
- return resultLineNumbers;
-
- }
+public class AnnotationConverterTest {
public static void ppp(String s) {
System.out.println("[AnnotationConverterTest] " + s);
@@ -89,7 +34,7 @@ private void checkOutput(String packageName, String fileName, String tag, List e
String packageDir = packageName.replace('.', File.separatorChar);
List<String> resultLines = new ArrayList<String>();
File file = new File(outputDir, packageDir + File.separatorChar + fileName);
- List<Integer> actualLineNumbers = grep(file, tag, resultLines);
+ List<Integer> actualLineNumbers = BaseTest.grep(file, tag, resultLines);
Assert.assertEquals(actualLineNumbers, expected, file + "\n tag:" + tag);
}
@@ -0,0 +1,23 @@
+package test.failedreporter;
+
+import org.testng.SkipException;
+import org.testng.TestNG;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class FailedReporterSampleTest {
+ @Test
+ public void f2() {
+ throw new RuntimeException();
+ }
+
+ @Test
+ public void f1() {
+ throw new SkipException("Skipped");
+ }
+
+ @Test
+ public void f3() {
+ }
+
+}
@@ -0,0 +1,49 @@
+package test.failedreporter;
+
+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.v6.Lists;
+
+import test.BaseTest;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+public class FailedReporterTest extends BaseTest {
+ private File mTempDirectory;
+
+ @BeforeMethod
+ public void setUp() {
+ File slashTmpDir = new File(System.getProperty("java.io.tmpdir"));
+ mTempDirectory = new File(slashTmpDir, "testng-tmp-" + System.currentTimeMillis() % 1000);
+ mTempDirectory.mkdirs();
+ mTempDirectory.deleteOnExit();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ deleteDir(mTempDirectory);
+ }
+
+ @Test
+ public void failedAndSkippedMethodsShouldBeIncluded() throws IOException {
+ TestNG tng = new TestNG();
+ tng.setVerbose(0);
+ tng.setTestClasses(new Class[] { FailedReporterSampleTest.class });
+ tng.setOutputDirectory(mTempDirectory.getAbsolutePath());
+ tng.run();
+
+ String[] expected = new String[] { "f1", "f2" };
+ File failed = new File(mTempDirectory, "testng-failed.xml");
+ for (String s : expected) {
+ List<String> resultLines = Lists.newArrayList();
+ BaseTest.grep(failed, "<include name=\"" + s + "\"/>", resultLines);
+ Assert.assertEquals(1, resultLines.size());
+ }
+
+ }
+}
View
@@ -88,6 +88,7 @@
<class name="test.testng195.AfterMethodTest" />
<class name="test.regression.BeforeTestFailingTest"/>
<class name="test.testng285.TestNG285Test" />
+ <class name="test.failedreporter.FailedReporterTest" />
</classes>
</test>

0 comments on commit d1bcd19

Please sign in to comment.