The example below assumes that the JUnit tests are called the suffix "Test", such as "MyClassTest.java", and that the Jar JUnit 4 file is located in the library directory pointed to by the lib.dir property. For each jar file containing compiled tests, ZipFileSet can be used to select test classes inside the nested <batchtest> element. The JUnit 4 jar path is included in the class path to ensure that the correct version is being used.
<target name="test" description="All the tests."> <junit fork="true"> <classpath> <fileset dir="war/WEB-INF/lib/" includes="**/*.jar" /> <fileset dir="${lib.dir}" includes="junit*.jar" /> </classpath> <batchtest haltonfailure="true"> <zipfileset src="war/WEB-INF/lib/test.jar" includes="**/*Test.class" /> </batchtest> <formatter type="plain" usefile="false" /> </junit> </target>
source share