Assertions in Eclipse when running JUnit tests

Our 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

Trackback URL for this post:

http://www.func.nl/trackback/98

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

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".