Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling assertions in Netbeans

I wanna do something like

java -enableassertions com.geeksanonymous.TestClass

How do I do this?

like image 594
andandandand Avatar asked Dec 10 '09 12:12

andandandand


People also ask

How do I enable assertions?

To configure assertion options one must use either the -ea or -da command line flags to enable or disable assertions with the command line tool: “java”. For example, “java -ea Assert” where Assert is a java class file. You may also specify a specific class or package as follows.

Is assertion enabled by default?

By default, assertions are disabled. Two command-line switches allow you to selectively enable or disable assertions. With no arguments, the switch enables assertions by default.

Can assertion be enabled for packages in java?

You could enable assertions for all packages, then disable them for some of the packages. Or otherwise- disable for all packages, then enable only for some of them.


2 Answers

With a Maven project in netbeans 7.0, choose "File" -> "Project Properties ()".

In the window that appears, choose "Run", and add -enableassertions to the "VM Options" textbox.

like image 63
MrDrews Avatar answered Oct 06 '22 00:10

MrDrews


I dont know about Netbeans, but you also can programmatically enable assertions (maybe that helps you as well).

public class WhenRunningTests() {

    static {
        ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
    }

    @Test(expected=AssertionError.class)
    public void assertionsShouldBeEnabled() {
        assert false;
    }
}
like image 42
akuhn Avatar answered Oct 05 '22 22:10

akuhn