JUnit: NoClassDefFoundError: org/junit/runner/mani

2019-04-04 20:53发布

问题:

This question already has an answer here:

  • java.lang.NoClassDefFoundError in junit 14 answers

When I try to run some unit tests, the following error is raised:

java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:320)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:310)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:305)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:283)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:207)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:191)

I have to mention that junit-4.11.jar is added to project build path. Any ideas?

回答1:

Even I was facing the same issue, so try the below steps -

  1. Right click the project in Package Explorer, and click Properties.
  2. Click the Libraries tab.
  3. Click the Add library button.
  4. Select JUnit and click Next.
  5. Select JUnit 4 (that's what I am using).
  6. Click finish.
  7. Now right click the file containing unit tests and select Properties.
  8. Under the Run/Debug settings, remove any entries from the Launch Configurations for that file. Hit ok.

Hopefully you'll be able to run the tests now.



标签: java junit