I'm using pure JUnit 4 test and I have them compiled inside some jars that belongs to the classpath. I'd like to run all the tests in my classpath.
Is there a way?
My tasks looks like:
<target name="test" description="All the tests">
<junit fork="yes">
<classpath>
<path refid="test.classpath" />
<fileset dir="war/WEB-INF/lib/">
<include name="*.jar"/>
</fileset>
<fileset dir="war/WEB-INF"/>
<fileset dir="war"/>
</classpath>
<formatter type="plain" usefile="false" />
</junit>
</target>
The example below assumes the JUnit tests are named with the suffix "Test" such as "MyClassTest.java" and that the JUnit 4 jar file is in a library directory pointed to by the property lib.dir
. For each jar file containing compiled tests, a ZipFileSet may be used to select the test classes within a nested <batchtest>
element. The path to the JUnit 4 jar is included in the classpath to ensure that the correct version is 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With