diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 1b5d72f5b..5f295ab5d 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -354,6 +354,12 @@ can be specified.
that your tests have written as some characters are illegal in XML documents and will be dropped. +The formatter named failure
collects all failing testXXX()
+methods and creates a new TestCase
which delegates only these
+failing methods. The name and the location can be specified via Java System property
+ant.junit.failureCollector
. The value has to point to the directory and
+the name of the resulting class (without suffix). It defaults to java-tmp-dir/FailedTests.
Note: Please read the Ant FAQ if you want to
set the fork attribute to true
, the includeAntRuntime
@@ -616,6 +622,50 @@ aborted. Results are collected in files named
TEST-
name.txt
and written to
${reports.tests}
.
+<target name="test"> + <property name="collector.dir" value="${build.dir}/failingTests"/> + <property name="collector.class" value="FailedTests"/> + <!-- Delete 'old' collector classes --> + <delete> + <fileset dir="${collector.dir}" includes="${collector.class}*.class"/> + </delete> + <!-- compile the FailedTests class if present --> + <javac srcdir="${collector.dir}" destdir="${collector.dir}"/> + <available file="${collector.dir}/${collector.class}.class" property="hasFailingTests"/> + <junit haltonerror="false" haltonfailure="false"> + <sysproperty key="ant.junit.failureCollector" value="${collector.dir}/${collector.class}"/> + <classpath> + <pathelement location="${collector.dir}"/> + </classpath> + <batchtest todir="${collector.dir}" unless="hasFailingTests"> + <fileset dir="${collector.dir}" includes="**/*.java" excludes="**/${collector.class}.*"/> + <!-- 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> ++
On the first run all tests are collected via the <batchtest/>
+element. It's plain
formatter shows the output on the console. The
+failure
formatter creates a java source file in
+${build.dir}/failingTests/FailedTests.java
which extends
+junit.framework.TestCase
and returns from a suite()
+method a test suite for the failing tests.
+On a second run the collector class exists and instead of the <batchtest/>
+the single <test/>
will run. So only the failing test cases are re-run.
+The two nested formatters are for displaying (for the user) and for updating the collector
+class.
+