JUnit 4 does not run latest changes on tests

17 Jun 2013

Today I faced the problem that newly created JUnit test cases were not run by JUnit in Eclipse.

As we are using Eclipse in combination with Maven we figured out that this was caused by a configuration problem of the project settings in Eclipse.

Maven’s default test output directory is target/test-classes whereas Eclipse puts its output to target/classes which is the default configuration. In order to get my JUnit 4 tests run again, I deleted the target/classes folder and reconfigured my project configuration by selecting the project, hitting Alt + Return. In the properties window navigate to “Java Build Path” and open up the “Source” tab. Now select the entry for your tests whatever/src/test/java and have a look at the textfield at the bottom. The content has to look like whatever/target/test-classes and not as in many cases whatever/target/classes. Change it to whatever/target/test-classes, hit ok and you should be ready to go.