views:

228

answers:

4

I wanna do something like

java -enableassertions com.geeksanonymous.TestClass

How do I do this?

+1  A: 

Check this link out. It will help to accomplish just that.

Pablo Santa Cruz
do I need that Execution Profile module? doesn't Netbeans have something built-in already for assertions?
omgzor
+1  A: 

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;
    }
}
Adrian
+1  A: 

The easiest way is to use the Run properties. The property is labeled 'VM Options'.

This tutorial has more detailed info and screen shots from NetBeans 5.5. The dialog is very similar in the most recent release of NetBeans; 6.8, which is available today.

vkraemer
A: 

Yes, it's a bug in NetBeans that it does not enable assertions when running unit tests (https://netbeans.org/bugzilla/show%5Fbug.cgi?id=139035). What Adrian suggests will work (although the test failed, yet assertions were enabled for the code that I was concerned with). Another way is to edit build-impl.xml and add in the macro definition for junit (just search for "junit").

Nathan Fiedler