Assertions in Eclipse when running JUnit tests
Submitted by martin on 14 May, 2009 - 08:05Our build server was complaining about tests that failed because assertions failed. While running the JUnit tests in Eclipse everything was fine. So I had to find out how to turn the assertions on in Eclipse.
After searching I found: http://codingclues.eu/2008/assertions-in-eclipse/ (in short: add "-ea" to the JVM arguments in the JUnit configuration).
I'm sure I will forget that when I create a new JUnit test, but found a solution for that: go to: Window -> Preferences -> Java -> Junit and tick: 'Enable assertions for new JUnit launch configurations'.
Enjoy asserting

Default arguments
I usually add the -ea option as default vm arguments in eclipse. This ensures that you not only get assertion failures during unit tests, but every other launch as well.
To do this go to Window > Settings > Java > Installed JREs. Edit the jre you're using and add '-ea' to the "Default VM Arguments"
I found that this helps in finding bug causes as early as possible.
Post new comment