Eclipse Won’t Run All My JUnit Tests

Here’s a Eclipse/JUnit4/Maven problem I came across, maybe this “solution” can help someone else.

I was using Eclipse to unit test some Maven projects in Java. I noticed that Eclipse only executed two out of my four JUnit4 unit tests. Right-clicking a test case and choosing “Run” on it gave me an error: “Unrooted test”. The more popular tips from Google (e.g. Nabble and Stack Overflow) suggested the code was ok, but still Eclipse was skipping my tests. Then I found this post on RTFM which said “recompile your code using mvn clean install“. Rediculously simple, but it worked for me. (Ironically, running Maven is something I normally do twenty times per day…)

The funny thing is that JUnitMax (which automatically runs all tests when a file is saved) managed to run the skipped tests even though Eclipse couldn’t! I could tell it correctly passed/failed the test when I changed it. I am still confused about that. :)