ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Lyon" <>
Subject RE: [antlist] How to install/configure JUnit task
Date Wed, 18 Jul 2001 17:50:16 GMT
T Master,

You may need to feed your <junit/> task a <pathelement/> parameter to pick
up the CLASSPATH for the unit tests you are trying to run. Just a quick
suggestion here, but you might have better luck if you install JUnit in it's
own directory and then add junit.jar to the end of your CLASSPATH
environment variable setting. Assuming you installed Junit3.7 in
C:\junit3.7, the following entry at the end of your CLASSPATH environment
variable establishes this setting:


You may then test your JUnit installation by running the following commands:

C:\>cd junit3.7<Enter>

java junit.textui.TestRunner junit.samples.AllTests

This is nice, because then you can run JUnit independent of Ant should you
ever wish to (while developing new JUnit test fixtures, etc.).

Then, try a bit of code like this:

		<!-- Run the JUnit tests for the Foo classes. -->
		<junit fork="yes"
		    <pathelement path="${java.class.path}"/>
		    <pathelement location="${build.classes.dir}"/>
		  <formatter type="xml"/>
		  <test name=""



Matthew Lyon
QA Engineer
Stargus, Inc.
300 Brickstone Square
c/o YAS Corporation, Fifth Floor
Andover, MA 01810
Phone: +1 (978) 749-0007x235
Fax: +1 (978) 749-2922
Mobile: +1 (617) 733-0944

-----Original Message-----
From: T Master []
Sent: Wednesday, July 18, 2001 1:34 PM
Subject: Re: [antlist] How to install/configure JUnit task

Thanks for responding.

I found the "optional.jar" on Ant's site.  This should be linked to from the
Library Dependencies page IMHO.  I had no clue an optional.jar file existed

I put my "junit.jar" and "optional.jar" in my ${ANT_HOME}/lib directory, to
avoid using a TaskDef (which by the way I could not get working).

I put this code in my build.xml:
    "<target name="jtest" depends="init">
            <test name="unittests.example.HelloWorldTest" />

The error I get is:
build.xml [72] Could not create task of type: junit. Common solutions are to
use taskdef to declare your task, or, if this is an optional task, to put
the optional.jar in the lib directory of your ant installation (ANT_HOME).


> If you insist on not having junit.jar in your CLASSPATH, remove
> optional.jar from ANT_HOME/lib as well to avoid classloader problems
> and add
> <taskdef name="junit"
>   <classpath>
>     <pathelement location="/path/to/junit.jar" />
>     <pathelement location="/path/to/optional.jar" />
>   </classpath>
> </taskdef>

So far, I've tried both solution which have not worked.  Using the taskdef
and stating the paths, with the result:
build.xml [68] taskdef class cannot be found

I'm either having problems because I'm a newbie, or I'm having bad day #2.

T Master

View raw message