JUnitTask
can run a single specific JUnitTest
using the test
element.
<target name="test-int-chars" depends="jar-test"> <echo message="testing international characters"/> <junit printsummary="no" haltonfailure="yes" fork="false"> <classpath refid="classpath"/> <formatter type="plain" usefile="false" /> <test name="org.apache.ecs.InternationalCharTest" /> </junit> </target>
runs a single junit test (org.apache.ecs.InternationalCharTest
) in the current VM using the path with id classpath
as classpath and presents the results formatted using the standard plain
formatter on the command line.
This task can also run batches of tests. The batchtest
element creates a BatchTest
based on a fileset. This allows, for example, all classes found in directory to be run as testcases.
For example,
<target name="run-tests" depends="dump-info,compile-tests" if="junit.present"> <junit printsummary="no" haltonfailure="yes" fork="${junit.fork}"> <jvmarg value="-classic"/> <classpath refid="tests-classpath"/> <sysproperty key="build.tests" value="${build.tests}"/> <formatter type="brief" usefile="false" /> <batchtest> <fileset dir="${tests.dir}"> <include name="**/*Test*" /> </fileset> </batchtest> </junit> </target>
this target finds any classes with a test
directory anywhere in their path (under the top ${tests.dir}
, of course) and creates JUnitTest
's for each one.
Of course, <junit>
and <batch>
elements can be combined for more complex tests. For an example, see the ant build.xml
target run-tests
(the second example is an edited version).
To spawn a new Java VM to prevent interferences between different testcases, you need to enable fork
. A number of attributes and elements allow you to set up how this JVM runs.
@since Ant 1.2
@see JUnitTest
@see BatchTest
|
|
|
|
|
|