IntelliJ IDEA – enable Java 1.4 assertions for Junit Run/Debug configurations

Posted: March 2, 2011 in IntelliJ IDEA, Java, maven
Tags: , , ,

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.

  1. Eric says:


  2. 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

  3. Nick says:

    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!

  4. eRez says:

    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.

  5. 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s