Apache Ant JUnit Task

This task is used to run tests from the JUnit testing framework. This task is depend on external libraries that are not included in Apache Ant distribution by default.

The junit.jar and ant.junit.jar both are required to run this task, so put these JAR's in ANT_HOME/lib location.

The <junit> element is used in build.xml file to implement this task. It also supports a nested element <classpath> which presents path-like structure.

Apache Ant Junit Task Attributes

AttributeDescriptionRequired
printsummaryIt prints summery of the test cases.No
forkRun the tests in a separate JVMNo
forkmodeIt controls how many JVMs get created if we want to fork test cases.No
haltonerrorIt stops the build process if any error occurs.No
errorpropertyThis property is set in error event.No
haltonfailureIt stops the build process if a test fails.No
timeoutIt cancels the individual tests if they don't finish in the given time.No
maxmemoryMaximum amount of memory to allocate to the forked JVM.No
jvmThe command used to invoke JVM.No
dirThe directory in which to invoke JVM.No
tempdir A directory where Ant should place temporary files. Noreloading Whether or not a new classloader should be instantiated for each test case. Noclonevm It makes a clone of the process running in JVM. No

Let's see some examples to understand the functionalities of this testing task.

Apache Ant JUnit Task Example

The above example is running a test case defined into TestCase.

This example runs a separate JVM and run test on it. The fork attribute will run a new JVM.





Latest Courses