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

newguy picture newguy · May 12, 2011 · Viewed 33k times · Source

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?

Answer

Tim Long picture Tim Long · Aug 13, 2012

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.