I am trying to run a JUnit 4.8.1 task in Ant 1.7.1. My IDE is Eclipse Helios. I’ve been banging my head on a brick wall for two days now and I can’t understand it. I am sure that I am reading other posts, this is a problem with the classpath, but I do not see where I am mistaken.
My JUnit4 test suite is defined as follows:
package mypackage.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ mypackage.tests.controller.AllTests.class })
public class AllTests {
}
... simple enough, but the test failed with a ClassNotFoundException
java.lang.ClassNotFoundException: mypackage.tests.AllTests
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
When I turn on the debug flag, I get the following trace from Ant:
(...)
[junit] Couldn't find junit/framework/TestCase.class
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar
fileset: Setup scanner in dir C:\eclipse\plugins with patternSet{ includes: [org.junit_4.8.1.v4_8_1_v20100427-1100/junit.jar] excludes: [] }
Finding class junit.framework.Test
Loaded from C:\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar junit/framework/Test.class
(...)
Obviously, the JUnit jar is in the classpath, and other classes such as Test.class are compiled, so why do I get the message "can't find TestClass.class"?
I tried adding JUnit.jar to the Ant class path in the Eclipse GUI, and this has the following effect:
(...)
[junit] Found C:\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar
(...)
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
(...)
- , , , !
, ... Eclipse.
!