Coding With Fun
Home Docker Django Node.js Articles FAQ

JUnit integrates Ant


May 25, 2021 Apache Ant


Table of contents


JUnit integrates Ant

JUnit is a unit testing framework for the Java language. I t's easy to use and easy to scale. T here are many JUnit extensions available. If you're not familiar with JUnit, you can www.junit.org the manual on the website.

This section will show you how to extend JUnit with Ant. Ant uses JUnit tasks directly.

The properties associated with the JUnit task are given below:

Property Describe
dir Indicates where the VM is called. This property will be ignored when the .fork is disabled.
Jvm Represents the command that calls the JVM. This property will be ignored when the .fork is disabled.
fork Represents running a test file in a separate java virtual machine.
errorproperty Indicates that when a JUnit fails, set the name of the property.
failureproperty Indicates that when a JUnit fails, set the name of the property.
haltonerror Indicates that the execution process is stopped when a test has an error.
haltonfailure Indicates that the process is stopped when a fault occurs.
printsummary Represents a simple statistic that tells Ant to present each test example.
showoutput Indicates that the Ant is informed that the output is on the log log file or formattor.
tempdir Represents the temporary file to which the Ant will be stored.
timeout Indicates that the testing process took too long and exceeded the setup time (millisecond level).

Let's continue with hello World Fax app on this topic and join the JUnit task.

The example given below shows the execution of a simple JUnit test example:

<target name="unittest">
   <junit haltonfailure="true" printsummary="true">
      <test name="com.tutorialspoint.UtilsTest"/>
   </junit>
</target>

The example given above shows the execution of the com.tutorialspoint.UtilsTest junit class. Run the code above and you'll see the following output:

test:
[echo] Testing the application
[junit] Running com.tutorialspoint.UtilsTest
[junit] Tests run: 12, Failures: 0, Errors: 0, Time elapsed: 16.2 sec
BUILD PASSED