You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Bryce Penberthy <br...@mail.amnesiac.net> on 2001/05/08 17:05:58 UTC

Junit task / Resources

Hello,

I have a JUnit test that will cause a class to try to load an XML file as
a URL resource.  If I run this straight from JUnit with the appropriate
CLASSPATH environment variable set then it works fine.  However if I try
to run this within the JUnit task, then the class is unable to find the
XML file.

Currently javac will output the classes to a build output directory, then
copy all .xml and .properties files over to this structure.  When the
JUnit task runs, I figured that I would just add the build output
directory to the classpath there.

I have a path refid that I am using for the <classpath> element, and I
have echo'ed it to verify that my build output directory exists
there.  It will run the test classes, but somehow never pick up the xml
file.  Currently I am not forking the JUnit process.

One twist that I have found is that if I specify the build output file in
the CLASSPATH environment variable before running Ant, then it works like
a charm.  However I am trying to get away from my build.xml file having
dependencies on environment variables..

Has anyone run into this problem?  Any help would be greatly appreciated.

Thank you

Bryce Penberthy



Re: Junit task / Resources

Posted by Nick Christopher <nw...@visionics.com>.
Someone already answered with an explanation... here's how I deal with it.
I don't use the junit task. Instead I do:

<target name="test" depends="build_tests" description="Run JUnit tests">
  <java classname="junit.textui.TestRunner" fork="yes"
        dir="${test.build.dir}" taskname="junit" failonerror="false">
      <arg value="test.UnitTests" />
      <classpath refid="test.classpath" />
  </java>
</target>

This runs junit in the directiory I want (${test.build.dir}) with the
classpath I want. (test.classpath).    I don't get all the
reporting support the task offers but honestly that stuff seemed too much
effort anyway.

Bryce Penberthy wrote:

> Hello,
>
> I have a JUnit test that will cause a class to try to load an XML file as
> a URL resource.  If I run this straight from JUnit with the appropriate
> CLASSPATH environment variable set then it works fine.  However if I try
> to run this within the JUnit task, then the class is unable to find the
> XML file.
>
> Currently javac will output the classes to a build output directory, then
> copy all .xml and .properties files over to this structure.  When the
> JUnit task runs, I figured that I would just add the build output
> directory to the classpath there.
>
> I have a path refid that I am using for the <classpath> element, and I
> have echo'ed it to verify that my build output directory exists
> there.  It will run the test classes, but somehow never pick up the xml
> file.  Currently I am not forking the JUnit process.
>
> One twist that I have found is that if I specify the build output file in
> the CLASSPATH environment variable before running Ant, then it works like
> a charm.  However I am trying to get away from my build.xml file having
> dependencies on environment variables..
>
> Has anyone run into this problem?  Any help would be greatly appreciated.
>
> Thank you
>
> Bryce Penberthy