Reputation: 182
I'm trying to set up an ANT build script which compile code, compile tests, run unittests and then build. These are all done through separate targets with dependencies i.e.
<target name="compile">
<javac>...
</target>
<target name="compile-tests" depends="compile">
<javac>...
</target>
<target name="unittest" depends="compile-tests">
<junit...
<test ...
<fail if="tests.failed" ..
</target>
<target name="build" depends="compile, unittest">
</target>
Each 'test' inside the 'junit' task focuses on one part of the application, (typically package by package) and points to a Junit TestSuite. This set up allows for all tests to be run when a build is called but this isn't ideal for day-to-day development.
I would like to be able to do 2 things:
My solution for (2) was to use multiple antcall tasks which isn't really best practice. During these calls different properties were set to run all the tests as they each required a different property:
<!-- test package p2 with ant unittest -Dtest.p2=true -->
<target name="unittest" depends="compile-tests">
<junit...
<test if="test.p1" ...
<test if="test.p2"
<fail if="tests.failed" ..
</target>
<target name="unittestall">
<property name="test.p1" value="true"/>
...
</target>
<target name="build" depends="compile, unittest">
<antcall target="unittestall" />
<antcall target="clean" />
<antcall target="compile" />
</target>
This gave the granularity I required but meant alot of work was duplicated and ant's dependency features weren't being used to their full.
So my question is: How can I best set up ANT and Junit so that all tests can be run as part of a build AND so that individual tests can be run?
Thankyou :)
from Joshua England
p.s. ANT 1.8 and Junit 4.10 :)
Upvotes: 0
Views: 1192
Reputation: 16255
Something like this?
<target name="unittest-p1"></target>
<target name="unittest-p2"></target>
<target name="unittest-p3"></target>
<target name="unittest" depends="unittest-p1, unittest-p2, unittest-p3/>
You could then run all the tests by passing the unittest target:
ant unittest
(or any target which depends on unittest)
And you could run any individual test of set of tests by invoking the appropriate target, e.g.
ant unittest-p1
If you would end up with a lot of duplication in multiple junit targets, you could tidy that up by putting all the common stuff into a macrodef.
Upvotes: 1