Published on

[Solved]: Eclipse JUnit Error: Class not found java. java.lang.ClassNotFoundException...

Problem:

Running into the following error when trying to run some Junit tests via Run As -> JUnit Test on Eclipse Enterprise Edition.

Class not found com.codinginformer.test.SeleniumTest
java.lang.ClassNotFoundException: com.codinginformer.test.SeleniumTest
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:766)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:490)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:513)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Solution:

This error could be due to not activating seperate output folders for each folder in your build path.

Try this potential solution and see if it works:

  1. Right click on your project -> Select Properties -> Select Java Build Path -> Select the Sources tab
  2. If you don't see the Output folder option in the dropdown list below your build folder make sure to enable the checkbox Allow output folder for source folders. Then double click Output folder
  3. In the following modal select Specific output folder. Then, enter the following output path for the enabled field: target/classes. Note: The specific output path name doesn't matter as much as you defining an explicit output path instead of using the default output path
  4. Select Ok -> Apply and Close. Finally Run the JUnit tests via Run As -> JUnit Test

Conclusion

Thanks for reading this blog post!

If you have any questions or concerns please feel free to post a comment in this post and I will get back to you when I find the time.

If you found this article helpful please share it and make sure to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.