4

でアサーション機能を有効にしたいant。私の antbuild.xmlでは、アサーションを有効にしようとして、次のように記述しました。

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

junit関数を 1 つだけ含むファイルにアサーションを入れ、

testAssertions() {
  assert false;
}

を実行するantと、アサーションの失敗はスローされません。この設定でアサーションを有効にするにはどうすればよいですか?

4

2 に答える 2

10

あなたの<assertions>サブエレメントは の子のよう<project>ですが、これは正しいですか?

<junit>ant タスクを介してテストを実行していると想定しています。これが正しければ、<assertions><enable/></assertions>サブ要素を子に<junit>することでうまくいくはずです。

于 2012-08-27T15:47:59.107 に答える
0

アサーションを有効にするために、編集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=

run.jvmargs=\
    -ea

これを行った後、実行するとアサーションが有効になりましたant run

于 2017-03-24T17:30:40.990 に答える