Assert

Answered

I've spent some time trying to set up my project to use assertions. The assert keywords are correctly highlighted in the editor, the code compiles nicely, but no AssertionError is ever thrown.

I have checked the "Enable "assert" keyword" box in the paths tab.

I have programmatically set the defaultAssertionStatus to true in my class.

When I compile and run the class inside idea, the assertion is ignored.

Any ideas?

I have also tried to enable assertions when building with Ant by adding the source="1.4" attribute to the javac target in my build.xml. Again no AssertionError is thrown.
I noted that idea 4 does not yet support Ant 1.6.* and the <assertions/> property. How would on accomplish the same thing in the ant version supported by idea4?.

I'm probably missing something obvious. Any help would be appreciated.

- T

7 comments
Comment actions Permalink

Running with JVM argument "-ea" should do it, if I understand your problem correctly.

0
Comment actions Permalink

Thanks keith,

I'm running the app under resin 2.1.12 and it complains about the -ea option. Don't know how to resolve it.....

Thanks for your reply,
- Torsten

0
Comment actions Permalink

Hmm, it should still work if I run a program inside of idea.
I assumed that checking the "enable assertions" box would adjust the JVM flags accordingly.

Where do I set the -ea option for the build-in idea JVM?

- Torsten

0
Comment actions Permalink

Use of assertions is specified in two places - when you compile (-source 1.4 or above) and when you run (-ea)

"enable assertions" enables them for compiling (and for IDEA syntax checking).

You need to run with assertions enabled (-ea) in order to see the exceptions. (and run with a JRE1.4 or above)

0
Comment actions Permalink

Torsten wrote:

Hmm, it should still work if I run a program inside of idea.
I assumed that checking the "enable assertions" box would adjust the JVM flags accordingly.

Where do I set the -ea option for the build-in idea JVM?

- Torsten

In your Run/Debug configuration under 'VM parameters'.

1
Comment actions Permalink

ANONYMOUS above wrote:

    In your Run/Debug configuration under 'VM parameters'.

This solution worked perfectly for me, except in Pycharm "VM parameters" is now just called "Parameters" in Run/Debug configurations.

In short, simply click Edit Configurations and type "-ea" in the "Parameters" field.

1
Comment actions Permalink

Thanks, it's really works! I just write in configuration "-ea" in field VM option.

0

Please sign in to leave a comment.