JUnit: NoClassDefFoundError: org/junit/runner/manipulation/Filter

后端 未结 3 1033
暗喜
暗喜 2021-02-05 08:50

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.for         


        
相关标签:
3条回答
  • 2021-02-05 08:55

    In my case the error had the same stack trace, (ending with java.lang.Class.forName0(Native Method)) but the error message was different:

    java.lang.VerifyError: (class: org/junit/runner/manipulation/Alphanumeric, method: create signature: (Lorg/junit/runner/manipulation/Ordering$Context;)Lorg/junit/runner/manipulation/Ordering;) Wrong return type in function

    The cause turned out to be that I had upgraded JUnit from 4.11 to 4.13.1, because GitHub's "dependabot" suggested so, on some public project of mine, and even created merge requests ready for me to accept, and I thought "sure, why not, what could possibly go wrong?" Conclusion: don't trust GitHub's dependabot.

    0 讨论(0)
  • 2021-02-05 08:59

    this error can be caused by adding the JUnit library to Modulepath rather than Classpath.

    in Eclipse the left most panel "Package Explorer" right click your project go down to properties then go to "Java Build Path" Click on "Classpath" NOT "Modulepath" click "Add Library..." then Junit.

    0 讨论(0)
  • 2021-02-05 09:08

    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.

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