JUnit class not found (not loading) in Eclipse


I get below error when I run jUnit test class n Eclipse:

Class not found com.ucc.csd.server.PhraseGeneratorTest
java.lang.ClassNotFoundException: com.ucc.csd.server.PhraseGeneratorTest
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:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:425)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Solution:
1. Right-click on the test class, go to "run as" option
2. Select "classpath" tab 
3. Select "user entries" option.
4. Click advanced.
5. Select "add folder" and click "Ok"

Sometimes you may have to right-click on project -> properties -> uncheck the default output directory. Then clean your project and run your jUnit tests.







As an Amazon Associate I earn from qualifying purchases.

2 comments:

  1. A more spesific solution is to add the jUnit test output to:
    classes - projectName/target

    ReplyDelete
  2. Thanks, this helped me with yet another stupid problem in Eclipse when the Maven m2eclipse plugin is used.

    ReplyDelete

Please be polite.

Post Scriptum

The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Posts

Most Popular Articles