DEV Community

Sean Atukorala
Sean Atukorala

Posted on

3 2

[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)
Enter fullscreen mode Exit fullscreen mode

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.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay