JUNIT Test class in Eclipse - java.lang.ClassNotFoundException

后端 未结 26 1922
栀梦
栀梦 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:20

    I tried all the answers described here but none worked, but found this thread where slomek solves the problem in a very easy manner. Just go to project -> properties --> java build path. Then move Junit to the top by hitting the up bottom to the right. Then everything compiles just fine.

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

    I had this problem and it was kind of tricky to realise what was wrong. The project had a dependency project with some error, which stopped the build from execute. When I remove this dependency problem, the project was built as expected.

    Ps.: I am working on a project that has many compilation errors, because we are porting an application that was converted from Delphi to Java, so I didn't care to the compilation error at the beginning, that's why it took me some time to find out the problem.

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

    There is one more possibility. I had the same problem just now and no one of the solutions here helped. Except removing and recreating of the project - I didn't want to try it. What did help, was to clean the project two times immediately one after another! Clean + build could be repeated any number of times - it won't help. Only clean+clean and after that build goes OK. (Eclipse 3.6). Of course, you should disable autobuild for that.

    Edit: This post has got its last plus on 15.11.2017. So, the problem (and the solution) remains actual.

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

    Another possible problem is a missing builder (it will prevent from your .class file from being built).

    Check that your .project file has the following lines

    <buildSpec>
      <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
      </buildCommand>
    </buildSpec>
    <natures>
      <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    
    0 讨论(0)
  • 2020-12-14 14:26

    In "Package Explorer" view, Right click your test class, then "Build Path">>"Include", it should be OK.

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

    I too faced the same exception, none of the solutions over internet helped me out. my project contains multiple modules. My Junit code resides in Web module. And it's referring to client module's code.

    Finally , I tried : Right click on (Web module) project -->build path--> source tab--> Link source --> added the src files location (Client module's)

    Thats it! It worked like a charm Hope it helps

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