Apache Ant - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

ANT JUnit Test

ANT JUnit Test

shape Introduction

JUnit is the unit framework in testing which helps in JAVA Programming to get quality products. It is known as xUnit and later changed to JUnit. ANT JUnit Test can be run automatically and uses JUnit task as a part of a build process.

shape Description

To start testing, create a test target based on compile. The junit can perform the following tasks like It also uses failureproperty while performing the event. If any of the event gets failed, it terminates the entire project. If the event fails, war file building would be not helpful.

shape Further Process

Now, include junit.jar in class path to use junit. Also, include build/classes directory in classpath.formatter that defines the type of format for test output. Here, HTML output is required and hence use XML format. Then, the test class is called and a report directory is attached to it by writing the resulting file. However, the resulting file will not be in readable format, so, it should be converted to HTML. For that, specification is given to fileset tag such that beginning with test and ending as XML.

shape Example

[java] <target name="test" depends="compile"> <junit failureproperty="testsFailed" /> <junit printsummary="yes" haltonfailure="yes" showoutput="yes" > <classpath> <pathelement path="${classpath}" /> <pathelement path="${build.dir.classes}" /> </classpath> <formatter type="xml" /> <batchtest fork="yes" todir="${reports.dir}/"> <fileset dir="${src.dir}"> <include name="**/*Test*.java"/> </fileset> </batchtest> </junit> [/java] JUnit Test report can be created as follows. [java] <junitreport todir="${reports.dir}"> <fileset dir="${reports.dir}" includes="TEST-*.xml"/> <report format="noframes" todir="${reports.dir}"/> </junitreport> </target> [/java]

shape More Info

Normally, JUnit Test Report looks like below. However, in this project the result will be different.

Summary

shape Key Points

  • JUnit is a unit framework.
  • Depends on compiled task.
  • Test output text can be changed as per the requirement.