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
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.
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.
Even I was facing the same issue, so try the below steps -
Hopefully you'll be able to run the tests now.