You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michael Olan <ol...@computer.org> on 2003/05/23 01:49:59 UTC
junit can't find test classes
This has been driving me nuts all day!
I've got some junit test classes that I know work, but I can't get a build
script to find them, although it seems like it does. Here's the target:
<target name="test" depends="compile" description="Execute unit tests">
<junit printsummary="yes" >
<formatter type="plain" />
<batchtest>
<fileset dir = "${build.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
Here's what it says when it runs:
test:
[junit] Running classes.AccountTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST classes.AccountTest FAILED
[junit] Running classes.AcctInTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST classes.AcctInTest FAILED
[junit] Running classes.AcctOutTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST classes.AcctOutTest FAILED
So this seems to indicate that it did in fact find the test classes, but
here's what the reports say about each test class:
Testsuite: classes.AccountTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
Caused an ERROR
classes.AccountTest
java.lang.ClassNotFoundException: classes.AccountTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
It must be something dumb I'm doing, but I sure can't see it.
Re: junit can't find test classes
Posted by James Black <jb...@ritchie.acomp.usf.edu>.
Quoting Michael Olan <ol...@computer.org>:
> This has been driving me nuts all day!
>
> I've got some junit test classes that I know work, but I can't get a
> build
> script to find them, although it seems like it does. Here's the
> target:
It finds it enough to run the test.
I have the same problem, haven't figured out what is going on, so I just copy
all of my jar files but the jar files with just my test classes, and it runs
fine. I copy them to /usr/java/jre/lib/ext and that seems to solve the problem,
but I would prefer to figure out why it isn't working the way you are doing it.
Re: junit can't find test classes
Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 24 May 2003, Michael Olan <ol...@computer.org> wrote:
> <pathelement location="${build.dir}"/>
> java.lang.NoClassDefFoundError: classes/AccountTest (wrong name:
> AccountTest)
I assume AccountTest is in the anonymous package and not in the
package "classes", right?
Then you'll want to use <pathelement location="${build.dir}/classes"/>
to point to the root of your class hierarchy instead of one level
above.
Stefan
RE: junit can't find test classes
Posted by Michael Olan <ol...@computer.org>.
If I run the following from the command line (in the project directory), I
get a green bar:
java -cp C:/java/eclipse/plugins/org.junit_3.8.1/junit.jar;build/classes
AccountTest
I added the following to the following to the <junit> task:
<classpath >
<pathelement path="C:/java/eclipse/plugins/org.junit_3.8.1/junit.jar"/>
<pathelement location="${build.dir}"/>
</classpath>
And an ant build gives:
test:
[junit] Running classes.AccountTest
[junit] java.lang.NoClassDefFoundError: classes/AccountTest (wrong name:
AccountTest)
...<snip>
Huh???
> -----Original Message-----
> From: Stefan Bodewig [mailto:bodewig@apache.org]
> Sent: Friday, May 23, 2003 1:53 AM
> To: user@ant.apache.org
> Subject: Re: junit can't find test classes
>
> On Thu, 22 May 2003, Michael Olan <ol...@computer.org> wrote:
>
> > So this seems to indicate that it did in fact find the test classes,
>
> <batchtest> did, but <batchtest> just reads your filesystem.
>
> To run the tests, the Java VM must be able to load the classes. Add a
> <classpath> element to your <junit> task that points to your build
> dir.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
Re: junit can't find test classes
Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 22 May 2003, Michael Olan <ol...@computer.org> wrote:
> So this seems to indicate that it did in fact find the test classes,
<batchtest> did, but <batchtest> just reads your filesystem.
To run the tests, the Java VM must be able to load the classes. Add a
<classpath> element to your <junit> task that points to your build
dir.
Stefan
Re: junit can't find test classes
Posted by Jacob Kjome <ho...@visi.com>.
Here's the relevant info from the following build file for running JUnit
tests and it works just fine....
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/prevayler/prevayler/build.xml
build.properties...
# ----- unit test setup ------
unit.test.includes=**/CheckpointPrevaylerTest.java \
,**/SnapShotPrevaylerTest.java \
,**/util/clock/ClockedTransactionTest.java \
,**/test/*Test*.java
unit.test.excludes=
build.xml...
<property name="unit.test.home" location="${basedir}/unit_tests" />
<property name="unit.test.report.home" location="${unit.test.home}/reports" />
<property name="src.test.home" location="${src.home}/test" />
<property name="log4j.system.variable.name" value="${app.name}.log.home" />
<property name="log4j.log.path" location="${basedir}/logs" />
<fileset dir="${src.test.home}" id="unit.test.files"
includes="${unit.test.includes}"
excludes="${unit.test.excludes}" />
<path id="build.test.classpath" >
<pathelement location="${build.home}" />
<path refid="build.classpath" />
</path>
<target name="test" depends="compile.test"
description="Runs JUnit tests" >
<mkdir dir="${unit.test.home}" />
<mkdir dir="${unit.test.report.home}" />
<junit dir="${unit.test.home}" printsummary="yes" haltonfailure="no"
fork="yes" >
<classpath refid="build.test.classpath" />
<sysproperty
key="${log4j.system.variable.name}"
value="${log4j.log.path}" />
<!--<sysproperty
key="log4j.configuration"
value="file:./log4j.xml" />-->
<formatter
type="xml"
usefile="yes" />
<batchtest todir="${unit.test.report.home}" >
<fileset refid="unit.test.files" />
</batchtest>
</junit>
<antcall target="-test.report.html" />
</target>
<target name="-test.report.html" >
<!--description="Convert the junit xml files to html" -->
<junitreport todir="${unit.test.report.home}" >
<fileset dir="${unit.test.report.home}" >
<include name="TEST-*.xml" />
</fileset>
<report
format="frames"
todir="${unit.test.report.home}/html" />
</junitreport>
</target>
Hope that helps.
Jake
At 07:49 PM 5/22/2003 -0400, you wrote:
>This has been driving me nuts all day!
>
>I've got some junit test classes that I know work, but I can't get a build
>script to find them, although it seems like it does. Here's the target:
>
><target name="test" depends="compile" description="Execute unit tests">
> <junit printsummary="yes" >
> <formatter type="plain" />
> <batchtest>
> <fileset dir = "${build.dir}">
> <include name="**/*Test.class"/>
> </fileset>
> </batchtest>
> </junit>
> </target>
>
>Here's what it says when it runs:
>
>test:
> [junit] Running classes.AccountTest
> [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
> [junit] TEST classes.AccountTest FAILED
> [junit] Running classes.AcctInTest
> [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
> [junit] TEST classes.AcctInTest FAILED
> [junit] Running classes.AcctOutTest
> [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
> [junit] TEST classes.AcctOutTest FAILED
>
>So this seems to indicate that it did in fact find the test classes, but
>here's what the reports say about each test class:
>
>Testsuite: classes.AccountTest
>Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
>
> Caused an ERROR
>classes.AccountTest
>java.lang.ClassNotFoundException: classes.AccountTest
> at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:140)
>
>It must be something dumb I'm doing, but I sure can't see it.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org