JUNIT Test class in Eclipse - java.lang.ClassNotFoundException

后端 未结 26 1923
栀梦
栀梦 2020-12-14 13:55

I\'m trying to run my junit test (to verify that a properties file loads correctly) but I get ClassNotFoundException although the class is there and all requir

相关标签:
26条回答
  • 2020-12-14 14:41

    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.

    0 讨论(0)
  • 2020-12-14 14:41

    I had this problem, in my case the problem relies in the compilation, I am using maven and test classes didn't compile.

    I fixed it by doing a maven install (it compiles all the files), also you can check for other reasons, that avoid test to compile like if your "run configurations" is skipping the tests to save time.

    0 讨论(0)
  • 2020-12-14 14:42

    Right click the project in the Explorer: Build Path -> Order and Export -> Select JRE System Library [jdk] and click Bottom button.

    0 讨论(0)
  • 2020-12-14 14:42

    Yet another variation.
    Somehow, my formerly working test classes appeared to be running from some other location; my edits would not execute when I ran the tests.

    I found that the output folder for my ${project_loc}src/test/java files was not what I expected. It had inadvertently been set to ${project_loc}target/classes. I set it properly in project properties, Java Build Path, Source tab.

    0 讨论(0)
  • 2020-12-14 14:43

    check properties->java build path -> libraries. there should be no errors, in my case there was errors in the maven. once I put the required jar in the maven repo, it worked fine

    0 讨论(0)
  • 2020-12-14 14:44

    what worked for me is to remove the runconfiguration of the test. Then right click the testclass and click run as junit test.

    now it recreates a correct run config for me.

    0 讨论(0)
提交回复
热议问题