I recently ran into a test discrepancy where my test was failing when running it via the maven surefire plugin, yet it passed when I ran it through IntelliJ’s JUnit runner.
After spending a ridiculous amount of time on this issue, I was finally able to pinpoint the discrepancy to the Java 1.4 introduced “assert” statement and the differences in the default behavior of the maven surefire plugin and the IntelliJ JUnit runner. The maven surefire plugin (v 2.7.2) enables JVM assertions by default. IntelliJ’s JUnit runner does not (v 9.0.4). My test in question happened to be failing due to a failing assert in an included xml parsing library.
To change the default behavior of the JUnit runner, edit the Run/Debug configurations, select Edit Defaults, select JUnit, and add “-ea” or “-enableassertions” to the VM parameters.
Thanks.
[…] https://devcheatsheets.wordpress.com/2011/03/02/intellij-idea-enable-java-1-4-assertions-for-junit-ru… […]
Thank you very much, maybe intellij should lhave it enabled by default, or have a checkbox for this on the defaults as I think eclipse have
Big thumbs up; ran into the exact same problem as you and sure enough, Java 1.4 assert’s keyword usage (as opposed to junit.framework.Assert#assertNotNull ) was the cause!
thanks! was puzzled for days as to why my intellij’s ‘assert’ fail, while running the same junit on eclipse has no problem.
the intellij had this argument while the eclipse didn’t.
Glad to hear this post helped you!
Simply wish to say your article is as astounding. The clearness for your publish is simply great and i could think you’re
a professional on this subject. Fine along with your permission allow me to snatch your RSS feed to keep up to
date with approaching post. Thanks 1,000,000 and please continue the
enjoyable work.