I am getting this error when running JUnit test in Eclipse:
Class not found com.myproject.server.MyTest
java.lang.ClassNotFoundException: com.myproject.serve
In my case I had a wrong maven directory structure.
Which should be like:
/src/test/java/ com.myproject.server.MyTest
After I fixed that - everything worked like a charm.
These steps worked for me.
After having tried everything here with no improvement, I solved my issue by just restarting Eclipse
I faced the same problem and I was able to fix it using @slomek's answer but the issue resurfaced after that.
I finally fixed it by adding my project's output folder to the JUnit test's run configuration. Steps are:
Project properties -> Java Build Path -> Default output folder
<project-folder>/bin
Run -> Run Configurations...
Classpath
tabUser Entries
- even if the project is already included there
Advanced -> Add folder
to add the output folderThis issue might be due to weird project setup in Eclipse - e.g. source folder with nested maven projects imported as a single project/folder (at least that was how my project was setup).
I had the similar problem with my Eclipse Helios which debugging Junits. My problem was little different as i was able to run Junits successfully but when i was getting ClassNotFoundException while debugging the same JUNITs.
I have tried all sort of different solutions available in Stackoverflow.com and forums elsewhere, but nothing seem to work. After banging my head with these issue for close to two days, finally i figured out the solution to it.
If none of the solutions seem to work, just delete the .metadata folder created in your workspace. This would create an additional overhead of importing the projects and all sorts of configuration you have done, but these will surely solve these issue.
Hope these helps.
Might be you forgotten to place the Main class and Test Case class in /src/test/java. Check it Once.