ANT Script to execute JUnit

To execute JUnit classes using ANT build, use the following ANT build script.

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="common">

<path id="test.classpath">
        <pathelement location="${basedir}/src/main/webapp/WEB-INF/classes"/>
       
        <fileset dir="${basedir}/src/main/webapp/WEB-INF/lib">
                <include name="**/*.jar"/>
        </fileset>
</path>

<target name="test">
        <junit haltonfailure="yes">
                        <formatter usefile="true" type="plain"/>
                        <classpath refid="test.classpath"/>
                        <batchtest todir="${basedir}/src/testReport/">
                                <fileset dir="${basedir}/src/main/webapp/WEB-INF/classes/">
                                        <include name="*Test*.class"/>
                                </fileset>
                        </batchtest>
        </junit>
</target>

</project>

When the above build.xml file is executed using ant, the JUnit classes in ${basedir}/src/main/webapp/WEB-INF/classes/ will be executed and the test results will be available in ${basedir}/src/testReport/ folder.

Technology: 

Search