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

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.

About these ads

, , ,

  1. #1 by Eric on May 23, 2011 - 5:57 pm

    Thanks.

  2. #2 by elespaciodejaimejaime on May 26, 2012 - 10:01 pm

    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. #3 by Nick on March 28, 2013 - 10:37 pm

    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!

  1. intellij enable assertions « Roger's woze

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: