java.lang.NoClassDefFoundError in junit
- Eclipse -> Top menu -> Run -> Run Configurations
- Delete all the occurrences of your test. Your test may appear as YourTest.Method_1(). Delete that as well.
- Re-run. Let Eclipse build a fresh configuration.
Addendum: Locally I have created a "User Library" and added to my projects which has
hamcrest-core-1.3.jar
junit-4.12.jar
- Right click your project in Package Explorer > click Properties
- go to Java Build Path > Libraries tab
- click on 'Add Library' button
- select JUnit
- click Next.
- select in dropdown button JUnit4 or other new versions.
- click finish.
- Then Ok.
The same problem can occur if you have downloaded JUnit jar from the JUnit website, but forgotten to download the Hamcrest jar - both are required (the instructions say to download both, but I skipped ahead! Oops)