简体   繁体   English

当任何JUnit测试失败时,如何让构建失败?

[英]How to let the build fail, when any JUnit test fails?

We use latest Hudson version together with ANT scripts to build our projects. 我们使用最新的Hudson版本和ANT脚本来构建我们的项目。 We have installed several extra plugins (like pmd, findbugs.. etc) to let a build get unstable, when a number of errors occur. 我们已经安装了几个额外的插件(比如pmd,findbugs等),当发生许多错误时,让构建变得不稳定。 Since we usually are above those numbers concerning pmd most builds are unstable. 由于我们通常高于有关pmd的数字,因此大多数构建都不稳定。

So sometimes it happens, that we notice too late, that there are several JUnit tests failing, since we are used to it, that the build is unstable. 所以有时它发生了,我们注意到太晚了,有几个JUnit测试失败,因为我们已经习惯了它,构建是不稳定的。 I know that increasing the number of allowed errors in PMD script would be a (temporary) solution as well as fixing most of them, but we would prefer a solution, where we could let a build just fail, when a junit test fails, or at least give it a special custom state, so we automatically get informed, that something is wrong with our tests. 我知道增加PMD脚本中允许的错误数量将是一个(临时)解决方案以及修复大多数错误,但是我们更喜欢一个解决方案,当junit测试失败时,我们可以让构建失败,或者至少给它一个特殊的自定义状态,所以我们会自动获知,我们的测试有问题。

Do you know any solution for this problem? 你知道这个问题的解决方案吗?

Try this: 尝试这个:

<junit haltonfailure="no" failureproperty="test.failed" ... >
...
</junit>
<fail message="Test failure detected, check test results." if="test.failed" />

This will run all tests, and will cause the build to fail if one test fails. 这将运行所有测试,如果一个测试失败,将导致构建失败。 Alternatively, if you want to just stop the build after a test fails, change the haltonfailure property to yes. 或者,如果您想在测试失败后停止构建,请将haltonfailure属性更改为yes。

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

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