I am getting this error when running JUnit test in Eclipse:
Class not found com.myproject.server.MyTest
java.lang.ClassNotFoundException: com.myproject.serve
Earlier, in this case, I always did mvn eclipse:eclipse
and restarted my Eclipse and it worked. After migrating to GIT, it stopped working for me which is somewhat weird.
Basic problem here is Mr Eclipse does not find the compiled class.
Then, I set the output folder as Project/target/test-classes which is by default generated by mvn clean install
without skipping the test and proceeded with following workaround:
Option 1: Set classpath for each test case
Eclipse ->Run ->Run Configurations ->under JUnit->select mytest -> under classpath tab->Select User Entries->Advanced->Add Folder -> Select ->Apply->Run
Option 2: Create classpath variable and include it in classpath for all the test cases
Eclipse ->Windows ->Classpath Variables ->New->[Name : Junit_test_cases_cp | path : ]->ok Then go to Eclipse->Run ->Run Configurations ->JUnit->select mytest ->under classpath tab ->Select User Entries->Advanced->Add classpath variables->Select Junit_test_cases_cp->ok->Apply->Run
This is the only thing currently working for me after trying all the suggestions online.
It can also be due to "[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?"
It seems compile issue. Run project as Maven test, then Run as JUnit Test.
Check if your project is opened as a Maven project and not just a regular Java project. Actually a no-brainer, but that is exactly the same reason why you might miss it.
Making some dummy change and saving the test class can solve the problem. It will build the .class automatically
In my case, only next steps helped me to resolve this issue: