如何让 Ant JUnit 任务运行所有测试,然后在任何测试失败时停止构建的其余部分 [英] How can I have the Ant JUnit task run all tests and then stop the rest of the build if any test has failed

查看:25
本文介绍了如何让 Ant JUnit 任务运行所有测试,然后在任何测试失败时停止构建的其余部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用如下目标通过 Ant 运行 JUnit:

I'm running JUnit via Ant using a target something like this:

<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" 似乎会导致构建在任何单个测试失败后立即停止,仅记录第一个失败的测试.将其设置为关闭"会导致整个构建成功(即使测试失败消息已写入输出).

haltonfailure="yes" seems to cause the build to halt as soon as any single test has failed, logging only the first failed test. Setting it to "off" causes the entire build to succeed (even though test failure messages are written to the output).

我希望它运行所有测试(即使一个测试失败),然后在任何测试失败时停止构建.

What I want it for all tests to be run (even if one has failed), and then the build to be stopped if any tests have failed.

可以这样做吗?

推荐答案

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

You can set the failureproperty attribute of the junit task, then test the property afterwards with the fail task:

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

这篇关于如何让 Ant JUnit 任务运行所有测试,然后在任何测试失败时停止构建的其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆