gpt4 book ai didi

ant - 如何让Ant JUnit任务运行所有测试,然后在任何测试失败的情况下停止其余的构建

转载 作者:行者123 更新时间:2023-12-03 12:06:44 26 4
gpt4 key购买 nike

我正在使用类似这样的目标通过Ant运行JUnit:

<target name="junit" depends="compile">
<mkdir dir="${report.dir}"/>
<junit printsummary="yes" haltonfailure="yes" showoutput="yes" >
<classpath>
<path refid="classpath"/>
<path location="${classes.dir}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>

<batchtest fork="yes" todir="${report.dir}">
<fileset dir="${src.dir}" includes="**/*Tests.java" />
</batchtest>
</junit>
</target>

我有一个这样的课:
public class UserTests extends TestCase {

public void testWillAlwaysFail() {
fail("An error message");
}
public void testWillAlwaysFail2() {
fail("An error message2");
}
}

一旦任何单个测试失败, haltonfailure="yes"似乎会导致构建停止,仅记录第一个失败的测试。将其设置为“off”会使整个构建成功(即使将测试失败消息写入输出中)。

我想要所有测试都运行(即使一个测试失败了),然后如果任何测试失败了,则停止构建。

是否有可能做到这一点?

最佳答案

您可以设置failureproperty任务的 junit 属性,然后再使用 fail 任务测试该属性:

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

关于ant - 如何让Ant JUnit任务运行所有测试,然后在任何测试失败的情况下停止其余的构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4038547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com