简体   繁体   English

在蚂蚁中启用断言

[英]enabling assertions in ant

I want to enable the assertion facility in ant . 我想在ant启用断言功能。 In my ant build.xml , I put the follows, trying to enable assertions. 在我的ant build.xml ,我将下面的内容尝试启用断言。

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

I put assertion in a junit file, which includes only one function, 我把断言放在一个junit文件中,该文件只包含一个函数,

testAssertions() {
  assert false;
}

when running ant , assertion fails are not thrown.. How to enable assertion in this setting? 运行ant ,不会抛出断言失败..如何在此设置中启用断言?

It looks like your <assertions> subelement is a child of <project> , is this correct? 看起来你的<assertions>子元素是<project>子元素,这是正确的吗?

I am assuming that you are running the test via the <junit> ant task. 我假设您正在通过<junit> ant任务运行测试。 If this is correct, making the <assertions><enable/></assertions> subelement a child of <junit> should work. 如果这是正确的,那么<assertions><enable/></assertions>子元素应该是<junit>子元素。

To enable assertions, I edited nbproject/project.properties and changed 为了启用断言,我编辑了nbproject/project.properties并进行了更改

# 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 . 执行此操作后,在执行ant run时启用了断言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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