How to run a simple JUnit test from a Jazz build definition?
When I generated a build definition from scratch a build.xml file was
generated that had the following template for running Junit tests... <target name="test"> <!-- Update the build progress in Jazz by setting the currentActivityLabel. --> <buildResultPublisher currentActivityLabel="testing..." buildResultUUID="${buildResultUUID}" repositoryAddress= "${repositoryAddress}" userName="${userName}" password="${password}" /> <!-- Pretend we're testing. --> <sleep seconds="3" /> <!-- Example usage of the junitLogPublisher to publish a JUnit log. JUnit results published in this way are shown on the JUnit tab of the build result editor. --> <junit> <test name="AllTests" outfile= "result"> <formatter type="xml" /> </test> </junit> <junitLogPublisher filePath="result.xml" buildResultUUID= "${buildResultUUID}" repositoryAddress= "${repositoryAddress}" userName="ADMIN" password="ADMIN" /> </target> All I did was change the name of the test to my project's JUnit test. But when I run this I get... test: BUILD FAILED C:\Documents and Settings\wulkan\Local Settings\Temp\Auction Project Team build\build.xml:166: Could not create task or type of type: junit. Ant could not find the task or a class this task relies upon. This is common and has a number of causes; the usual solutions are to read the manual pages then download and install needed JAR files, or fix the build file: - You have misspelt 'junit'. Fix: check your spelling. - The task needs an external JAR file to execute and this is not found at the right place in the classpath. Fix: check the documentation for dependencies. Fix: declare the task. - The task is an Ant optional task and the JAR file and/or libraries implementing the functionality were not found at the time you yourself built your installation of Ant from the Ant sources. Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the task and make sure it contains more than merely a META-INF/MANIFEST.MF. If all it contains is the manifest, then rebuild Ant with the needed libraries present in ${ant.home}/lib/optional/ , or alternatively, download a pre-built release version from apache.org - The build file was written for a later version of Ant Fix: upgrade to at least the latest release version of Ant - The task is not an Ant core or optional task and needs to be declared using <taskdef>. - You are attempting to use a task defined using <presetdef> or <macrodef> but have spelt wrong or not defined it at the point of use Remember that for JAR files to be visible to Ant tasks implemented in ANT_HOME/lib, the files must be in the same directory or on the classpath Please neither file bug reports on this problem, nor email the Ant mailing lists, until all of these causes have been explored, as this is not an Ant bug. Anyone have any idea what I am missing? Mike Wulkan |
5 answers
There are many issues with running Junit tests from Ant. You can't
simply uncomment the Junit task in the example build.xml. If you were to run a vanilla Ant script from within Eclipse you would see the same problem. The Apache site has information on how to get it working. See: http://ant.apache.org/manual/OptionalTasks/junit.html for further information. Jim D'Anjou wulkan@ca.ibm.com wrote:
|
Jim D'Anjou wrote:
There are many issues with running Junit tests from Ant. You can't Well I think I have managed to track down the solution. 1) First you have to copy the junit.jar from your eclipse junit plugin into the $ANT_HOME/lib directory on the build machine. You can find the location of the $ANT_HOME directory in the build definition properties (see anthome.png attachment). 2) You have to add your builds working directory path to the <junit> step: <classpath> <pathelement path="${classpath}"/> <pathelement location="working-dir"/> </classpath> The full <junit> step looks like: <junit> <classpath> <pathelement path="${classpath}"/> <pathelement location="working-dir"/> </classpath> <test name="com.ibm.sample.AllTests" outfile="result"> <formatter type="xml" /> </test> </junit> Mike Wulkan |
Mike Wulkan wrote:
Mike, Did you try just bringing over the junit plugin as a whole instead? It would seem more clean to add a plugin to the build system rather than to perform surgery on a plugin that is already there. I would hope that Eclipse Ant support would handle the classpath issues for that configuration. Just a thought, Steve |
Steve Wasleski wrote:
Mike Wulkan wrote: I didn't try that specifically, but I did try just adding a <pathelement location="..." > statement to point to the JUnit.jar. According to the ANT documentation that should have worked but it didn't. The only thing that worked was actually putting the jar in the Ant Home directory itself. I'll try your suggestion though. All this begs the question as to why the sample buld.xml file produced by the build definition wizard falls so short of actually working. If it is going to generate a template for running JUnit tests, then that template should either work out-of-the-box, or at least have enough instructions in the comments to tell the user what needs to be done to get it to work. Thanks, Mike |
The commented out junit and javac task invocations where not meant to be
"uncommented and run". The generated sample build file will be updated so it doesn't give this impression. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.