Monday, July 7, 2008

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 Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

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.