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:

;C:\junit3.7\junit.jar

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"
                       dir="${build.classes.dir}"
                       printsummary="yes"
                       haltonfailure="yes">
                  <classpath>
                    <pathelement path="${java.class.path}"/>
                    <pathelement location="${build.classes.dir}"/>
                  </classpath>
                  <formatter type="xml"/>
                  <test name=".com.biz.foo.AllJUnitFooTests"
                        todir=".\JUnit_Reports"/>
                </junit>

Cheers,

Matt

*********************************
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
E-Mail: [EMAIL PROTECTED]
http://www.stargus.com

-----Original Message-----
From: T Master [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 18, 2001 1:34 PM
To: [EMAIL PROTECTED]
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
before.

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">
        <junit>
            <test name="unittests.example.HelloWorldTest" />
        </junit>
    </target>"


The error I get is:
init:
jtest:
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).


Ideas?

> 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"
>
classname="org.apache.tools.ant.taskdef.optional.junit.JUnitTask">
>   <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
org.apache.tools.ant.taskdef.optional.junit.JUnitTask cannot be found


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

T Master




Reply via email to