JUNIT Test class in Eclipse - java.lang.ClassNotFoundException

Mouna Cheikhna picture Mouna Cheikhna · Apr 19, 2011 · Viewed 153.1k times · Source

I'm trying to run my junit test (to verify that a properties file loads correctly) but I get ClassNotFoundException although the class is there and all required libraries are there too.

Here it is the error I get :

Class not found ConfigurationManagerTest                                                 java.lang.ClassNotFoundException: ConfigurationManagerTest
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

any ideas on how to fix this ?

Thanks.

Answer

Alan Escreet picture Alan Escreet · Apr 19, 2011

ConfigurationManagerTest is not being found on your classpath. Ensure that the ConfigurationManagerTest.class file is available on your classpath.

It might not exist if it wasn't successfully compiled or if it's being created in a directory that you haven't told the Eclipse project should be on the classpath.

Assuming that you've put your test classes in a separate folder, make sure that it shows up in the "Package Explorer" view (rather than the "Navigator" view).

Under the project properties, "Java Build Path" and the "Source" tab, you can also see if the source folder is included for building as well as where the .class files are generated.