>New Revision: 563053 > >URL: http://svn.apache.org/viewvc?view=rev&rev=563053 >Log: >New JUnit formatter: collects failing test cases (testXXX methods) for a rerun. >* works from command line >* its own JUnit test scenario fails (for - to me - unknown reason)
Some ideas why the junit testcase fails and the run from the command line not? Jan >+ <target name="failureRecorder.prepare"> >+ <property name="tmp.dir" value="out"/> >+ <mkdir dir="${tmp.dir}/org"/> >+ <echo file="${tmp.dir}/A.java"> >+ import junit.framework.*; >+ public class A extends TestCase { >+ public A(String s) { super(s); } >+ public void test01() { System.out.println("A.test01"); } >+ public void test02() { System.out.println("A.test02"); fail(); } >+ public void test03() { System.out.println("A.test03"); fail(); } >+ } >+ </echo> >+ <echo file="${tmp.dir}/B.java"> >+ import junit.framework.*; >+ public class B extends TestCase { >+ public B(String s) { super(s); } >+ public void test04() { System.out.println("B.test04"); fail(); } >+ public void test05() { System.out.println("B.test05"); } >+ public void test06() { System.out.println("B.test06"); } >+ } >+ </echo> >+ <echo file="${tmp.dir}/C.java"> >+ import junit.framework.*; >+ public class C extends TestCase { >+ public C(String s) { super(s); } >+ public void test07() { System.out.println("C.test07"); } >+ public void test08() { System.out.println("C.test08"); } >+ public void test09() { System.out.println("C.test09"); } >+ } >+ </echo> >+ <echo file="${tmp.dir}/org/D.java"> >+ package org; >+ import junit.framework.*; >+ public class D extends TestCase { >+ public D(String s) { super(s); } >+ public void test10() { System.out.println("D.test10"); fail(); } >+ } >+ </echo> >+ <javac srcdir="${tmp.dir}" destdir="${tmp.dir}"/> >+ </target> >+ >+ <target name="failureRecorder.internal"> >+ <property name="tmp.dir" value="out"/> >+ <!-- >+ <delete> >+ <fileset dir="${tmp.dir}" includes="FailedTests*.class"/> >+ </delete> >+ --> >+ <!-- compile the FailedTests class if present --> >+ <javac srcdir="${tmp.dir}" destdir="${tmp.dir}"/> >+ <available file="${tmp.dir}/FailedTests.class" property="hasFailingTests"/> >+ <junit haltonerror="false" haltonfailure="false"> >+ <sysproperty key="ant.junit.failureCollector" value="${tmp.dir}/FailedTests"/> >+ <classpath> >+ <pathelement location="${tmp.dir}"/> >+ </classpath> >+ <batchtest todir="${tmp.dir}" unless="hasFailingTests"> >+ <fileset dir="${tmp.dir}" includes="**/*.java" excludes="**/FailedTests.*"/> >+ <!-- for initial creation of the FailingTests.java --> >+ <formatter type="failure"/> >+ <!-- I want to see something ... --> >+ <formatter type="plain" usefile="false"/> >+ </batchtest> >+ <test name="FailedTests" if="hasFailingTests"> >+ <!-- update the FailingTests.java --> >+ <formatter type="failure"/> >+ <!-- again, I want to see something --> >+ <formatter type="plain" usefile="false"/> >+ </test> >+ </junit> >+ </target> >+ >+ <target name="failureRecorder.runtest"> >+ <ant target="failureRecorder.internal" antfile="junit.xml" inheritAll="false"/> >+ </target> >+ >+ <target name="failureRecorder.fixing"> >+ <property name="tmp.dir" value="out"/> >+ <echo file="${tmp.dir}/A.java"> >+ import junit.framework.*; >+ public class A extends TestCase { >+ public A(String s) { super(s); } >+ public void test01() { System.out.println("A.test01"); } >+ public void test02() { System.out.println("A.test02"); } >+ public void test03() { System.out.println("A.test03"); } >+ } >+ </echo> >+ </target> >+ >+ /* Bugzilla Report 42984 */ >+ //TODO This scenario works from command line, but not from JUnit ... >+ // See the _run.bat attachement of the bug. >+ public void _testFailureRecorder() { >+ File testDir = new File(getProjectDir(), "out"); >+ File collectorFile = new File(getProjectDir(), "out/FailedTests.java"); >+ >+ // ensure that there is a clean test environment >+ assertFalse("Test directory must not exist before the test preparation.", >+ testDir.exists()); >+ assertFalse("The collector file must not exist before the test preparation.", >+ collectorFile.exists()); >+ >+ // prepare the test environment >+ executeTarget("failureRecorder.prepare"); >+ assertTrue("Test directory was not created.", testDir.exists()); >+ assertTrue("There should be one class.", (new File(testDir, "A.class")).exists()); >+ assertFalse("The collector file " + collectorFile.getAbsolutePath() >+ + " should not exist before the 1st run.", collectorFile.exists()); >+ >+ // 1st junit run: should do all tests - failing and not failing tests >+ executeTarget("failureRecorder.runtest"); >+ assertTrue("The collector file " + collectorFile.getAbsolutePath() >+ + " should exist after the 1st run.", collectorFile.exists()); >+ // the passing test cases >+ assertOutputContaining("1st run: should run A.test01", "A.test01"); >+ assertOutputContaining("1st run: should run B.test05", "B.test05"); >+ assertOutputContaining("1st run: should run B.test06", "B.test06"); >+ assertOutputContaining("1st run: should run C.test07", "C.test07"); >+ assertOutputContaining("1st run: should run C.test08", "C.test08"); >+ assertOutputContaining("1st run: should run C.test09", "C.test09"); >+ // the failing test cases >+ assertOutputContaining("1st run: should run A.test02", "A.test02"); >+ assertOutputContaining("1st run: should run A.test03", "A.test03"); >+ assertOutputContaining("1st run: should run B.test04", "B.test04"); >+ assertOutputContaining("1st run: should run D.test10", "D.test10"); >+ >+ // 2nd junit run: should do only failing tests >+ executeTarget("failureRecorder.runtest"); >+ assertTrue("The collector file " + collectorFile.getAbsolutePath() >+ + " should exist after the 2nd run.", collectorFile.exists()); >+ // the passing test cases >+ assertOutputNotContaining("2nd run: should not run A.test01", "A.test01"); >+ assertOutputNotContaining("2nd run: should not run A.test05", "B.test05"); >+ assertOutputNotContaining("2nd run: should not run B.test06", "B.test06"); >+ assertOutputNotContaining("2nd run: should not run C.test07", "C.test07"); >+ assertOutputNotContaining("2nd run: should not run C.test08", "C.test08"); >+ assertOutputNotContaining("2nd run: should not run C.test09", "C.test09"); >+ // the failing test cases >+ assertOutputContaining("2nd run: should run A.test02", "A.test02"); >+ assertOutputContaining("2nd run: should run A.test03", "A.test03"); >+ assertOutputContaining("2nd run: should run B.test04", "B.test04"); >+ assertOutputContaining("2nd run: should run D.test10", "D.test10"); >+ >+ // "fix" errors in class A >+ executeTarget("failureRecorder.fixing"); >+ >+ // 3rd run: four running tests with two errors >+ executeTarget("failureRecorder.runtest"); >+ assertTrue("The collector file " + collectorFile.getAbsolutePath() >+ + " should exist after the 3rd run.", collectorFile.exists()); >+ assertOutputContaining("3rd run: should run A.test02", "A.test02"); >+ assertOutputContaining("3rd run: should run A.test03", "A.test03"); >+ assertOutputContaining("3rd run: should run B.test04", "B.test04"); >+ assertOutputContaining("3rd run: should run D.test10", "D.test10"); >+ >+ // 4rd run: two running tests with errors >+ executeTarget("failureRecorder.runtest"); >+ assertTrue("The collector file " + collectorFile.getAbsolutePath() >+ + " should exist after the 4th run.", collectorFile.exists()); >+ assertOutputNotContaining("4th run: should not run A.test02", "A.test02"); >+ assertOutputNotContaining("4th run: should not run A.test03", "A.test03"); >+ assertOutputContaining("4th run: should run B.test04", "B.test04"); >+ assertOutputContaining("4th run: should run D.test10", "D.test10"); >+ } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]