You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by andy wix <st...@hotmail.com> on 2005/12/05 16:48:45 UTC

JUnit task

Hi,
I am having difficulty setting the classpath for this.
If I have a testing directory under the basedir (and these tests are in the 
testing package) what classpath do I need to define to use batch tests?

So I want to be able to run all the test classes in that directory:

<target name="test" >
  <junit printsummary="withOutAndErr" showoutput="yes">
  <formatter type="brief" usefile="false"/>
    <batchtest fork="yes">
      <fileset dir="testing">
        <include name="**/*Test.class"/>
      </fileset>
    </batchtest>
  </junit>
</target>

When I run this I get:
[junit] Null Test: Caused an ERROR
[junit] MyTest
[junit] java.lang.ClassNotFoundException: MyTest
[junit] at java.lang.Class.forName(Class.java:131)

so it seems the fileset bit works (finds the test) but JUnit doesn't have 
the classpath.

Thanks,
Andy

_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! 
http://www.msn.co.uk/newsletters


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: JUnit task

Posted by Dominique Devienne <dd...@gmail.com>.
> >That's given your basedir as a pathelement - how about giving it the
> >"testing" directory instead? Isn't that the base of the testing classes?
>
> But I think that is correct.
> The base dir is, say, xxx.  The testing dir sits below this with tests that
> are in the testing package.
> So sitting in my xxx dir (where I run ant from) the classpath for these
> tests is testing.MyTest1 etc.

Ah, ok. I think I see where this is going (maybe ;-). Sounds like
your <batchtest> <fileset> should be using the base base directory
as the classpath, to yield the same relative paths.

So assuming your compiled test classes are in ${basedir}/, one of them
being testing.MyTest1, corresponding to
${basedir}/testing/MyTest1.class, you should be using something along
the lines of:

<target name="test" >
  <property name="test.classes" location="." />
  <junit printsummary="withOutAndErr" showoutput="yes">
    <classpath>
      <pathelement location="${test.classes}" />
      <pathelement location=".../junit.jar" />
    </classpath>
    <formatter type="brief" usefile="false"/>
    <batchtest fork="yes">
      <fileset dir="${test.classes}">
        <include name="**/*Test.class"/>
      </fileset>
    </batchtest>
  </junit>
</target>

Notice how I've used the same dir in the classpath and the fileset. I
didn't really need to use a property, but it makes it more obvious
these should be the same dir.

Let us know if we got this right this time. --DD

PS: It is unusual to have test code not depend on something else. It
probably means you mix test code and the production code tested, or at
least the compiled classes for both.

PPS: Compiled classes are build products. I'm very much a proponent to
have all build products go into a single directory, usually called
build/ for me, which can easily be removed with Ant or the command
line.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: JUnit task

Posted by andy wix <st...@hotmail.com>.
Phew, got there in the end....thanks for the help.

<project name="MyProject" default="test" basedir=".">

<target name="test">
<junit printsummary="withOutAndErr" showoutput="yes">
  <classpath>
    <pathelement location="/home/andy/junit3.8.1/junit.jar" />
    <pathelement location="." />
  </classpath>
  <formatter type="brief" usefile="true" />
  <batchtest>
  <fileset dir=".">
    <filename name="testing/*Test.class" />
  </fileset>
  </batchtest>
  </junit>
  </target>
  </project>

cheers
Andy

_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! 
http://www.msn.co.uk/newsletters


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: JUnit task

Posted by andy wix <st...@hotmail.com>.
>That's given your basedir as a pathelement - how about giving it the 
>"testing" directory instead? Isn't that the base of the testing classes?

But I think that is correct.
The base dir is, say, xxx.  The testing dir sits below this with tests that 
are in the testing package.
So sitting in my xxx dir (where I run ant from) the classpath for these 
tests is testing.MyTest1 etc.

If I try your suggestion I get the same problem.

Thanks.

_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 
7.5 today! http://messenger.msn.co.uk


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: JUnit task

Posted by andy wix <st...@hotmail.com>.
> > so it seems the fileset bit works (finds the test) but JUnit doesn't 
>have
> > the classpath.
>
>Simply because you didn't provide any ;-)
>
>You'd need a nested <classpath> (within <junit>) with at least your
>"testing" directory, and any other jar(s) or directory(ies) required
>to run the tests. --DD
>

At the danger of sounding like I want this spoon fed....

I have tried every combination I can think of.  My tests only depend on 
JUnit so I can't see why the following gives the same error (declared inside 
the junit tag)..
         <classpath>
           <pathelement location="/home/andy/junit3.8.1/junit.jar"/>
           <pathelement location="${basedir}"/>
         </classpath>

Thanks

_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 
7.5 today! http://messenger.msn.co.uk


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: JUnit task

Posted by Dominique Devienne <dd...@gmail.com>.
> <target name="test" >
>  <junit printsummary="withOutAndErr" showoutput="yes">
>  <formatter type="brief" usefile="false"/>
>    <batchtest fork="yes">
>      <fileset dir="testing">
>        <include name="**/*Test.class"/>
>      </fileset>
>    </batchtest>
>  </junit>
> </target>
>
> so it seems the fileset bit works (finds the test) but JUnit doesn't have
> the classpath.

Simply because you didn't provide any ;-)

You'd need a nested <classpath> (within <junit>) with at least your
"testing" directory, and any other jar(s) or directory(ies) required
to run the tests. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org