Reputation: 39
Here is the situation:
I have a java application (netbeans project) that uses several java libraries (each of them is a netbeans project). I have an automated build script that builds the application using ant without the netbeans IDE. The command to build the application is
ant jar
That works fine, it recursively builds jars for all dependent libraries and finally the application jar.
Now, I want to run all my unit tests in the automated build. The default ant target depends on the targets jar
, test
, and javadoc
, so I thought I could simply call
ant
as the build command. As before, all jars are built for the dependent libraries, but only the unit tests for the application project are executed (same for javadoc, btw.).
So, how do I get ant to run the unit tests for each dependent library project recursively?
Used versions are: netbeans 8, junit 4.
The only solution I found is to add a dependency into the build.xml
used by ant for every library and the application project:
<target name="-pre-jar" depends="test" />
But that would mean to execute all tests on every build of a jar file. And since netbeans uses these build.xml
files as well, every simple build would lead to executing all unit tests.
Upvotes: 1
Views: 87
Reputation: 39
After some testing I think I've found a solution that works.
I had to add the following code into the build.xml
of each netbeans project whose unit tests should be run (fyi: the build.xml
is provided by netbeans for personal changes to the build process).
<target name="-pre-jar" depends="test-on-release" />
<target name="test-on-release" if="release.runtests">
<antcall target="test" />
</target>
Then, if I run ant on the commandline I have to define the property release.runtests
to enable the execution of unittests:
ant -Drelease.runtests= jar
If I remove the definition of the property from the call, the target test-on-release is not executed and thus the tests are not run. The same happens when I use the netbeans IDE to build a project.
That said, it is a solution, not the solution, at least not the solution I had hoped for. It would be much more convenient if there was a way to run the test target recursively without having to edit all these build.xml
files. Maybe that is not possible with the constraints given by the netbeans-generated build files.
Upvotes: 1