Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven)

I have just upgraded my SpringSource Tools Suite (STS, a variant IDE of Eclipse) to the latest version (v3.6.1). Then all my JUnit unit tests can not be run again. I am getting this error:

Class not found ClassToTest
java.lang.ClassNotFoundException: ClassToTest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

According to this blog: ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven), it is because of some misconfiguration of Maven plugin in Eclipse. However, in STS 3.6.2 I cannot find this option "Include Modules" in the Maven plugin. How can I fix this problem and re-enable my unit tests?

like image 417
newguy Avatar asked May 12 '11 06:05

newguy


People also ask

How do I fix junit initialization error?

Right click your project in Package Explorer > click Properties go to Java Build Path > Libraries tab click on 'Add Library' button select JUnit click Next.

What do we used to run unit test with Maven?

We can run our unit tests with Maven by using the command: mvn clean test.


1 Answers

There are still some back-draws on the current m2e plugin. Unit-test-cases couldn't be run as their including project grouped in a working-set. Following may help:

  1. Right click on project including junit-tests.
  2. Select Maven -> Disable Workspace Resolution

Try then to run your test again.

like image 51
Tim Long Avatar answered Sep 27 '22 18:09

Tim Long