简体   繁体   中英

enabling assertions in ant

I want to enable the assertion facility in ant . In my ant build.xml , I put the follows, trying to enable assertions.

<project> ... <assertions> <enable/> </assertions> </project>

I put assertion in a junit file, which includes only one function,

testAssertions() {
  assert false;
}

when running ant , assertion fails are not thrown.. How to enable assertion in this setting?

It looks like your <assertions> subelement is a child of <project> , is this correct?

I am assuming that you are running the test via the <junit> ant task. If this is correct, making the <assertions><enable/></assertions> subelement a child of <junit> should work.

To enable assertions, I edited nbproject/project.properties and changed

# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=

to

run.jvmargs=\
    -ea

After doing this, assertions were enabled when I executed ant run .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM