我正在编写一个委托(delegate)给 ant.junit
的 Gradle 任务. (是的,这就是我想要做的)。
当测试失败时,我不能让构建失败。
// this will fail
task breakit << {
ant.property(name: "broken", value: "!")
ant.fail(if: 'broken')
}
// this doesn't fail, even though running JUnit against java.lang.String fails.
task breakit << {
ant.junit(failureproperty: 'broken') { test(name: 'java.lang.String') }
ant.fail(if: 'broken')
}
两次调用
ant.fail
的行为应该相同。 .楼盘broken
应该设置,但在第二个版本中它不是。构建响应::breakit
[ant:junit] TEST java.lang.String FAILED
BUILD SUCCESSFUL
使用
haltonfailure: 'yes'
也不起作用 - 构建仍然成功。我怎样才能使构建失败的测试失败?
最佳答案
您使用的是哪个版本的 gradle?在 2.2.1 版本中,
ant.junit(printsummary: 'on', showoutput: 'yes', haltonfailure: 'no', failureproperty: 'failed', errorproperty: 'errored') {
}
ant.fail(if: 'failed')
ant.fail(if: 'errored')
对我有用。您甚至可以通过尝试以下简单代码来确认:
ant.failed = 'true'
ant.fail(if: 'failed')
关于ant - gradle build 中的 ant.junit 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857729/