My unit tests use the main
entry point in each of my Java classes. I'm using Eclipse. It's been risky to rely on the test results because sometimes I've forgotten to set -enableassertions
in the JVM arguments. Is there a universal setting that applies to all current and future Run Configurations
?

- 10,644
- 14
- 70
- 114
3 Answers
To make assertions enabled by default, first go to the Eclipse menu named Window
because Eclipse is a GUI application so it seems to be an excellent reason to put it in a menu called "Window".
Window > Preferences > Java > Installed JREs
Select the JRE that you use.
Click Edit
. Add to the Default VM Arguments
textbox the option -enableassertions
. Click Apply
if necessary.
Now, even without enabling assertions in the launch configuration, which seems to be synonymous with run configuration, programs run in Eclipse will have assertions enabled.

- 10,644
- 14
- 70
- 114
-
You (correctly I think) answered your own question. Why not accept this answer then? – Stuart Rossiter Jan 11 '17 at 16:28
Please don't use the Java assert
in unit tests.
This kind of assertion can be disabled because it is not intended to be used in unit tests at all. This assert only helps you to ensure some conditions at runtime of your actual code. Unit tests are different and done with special means as like JUnit
There are plenty good ressources to learn about proper unit testing, I would like to propose this as a possible starting point.

- 795
- 7
- 20