我怎么能有蚂蚁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

查看:476
本文介绍了我怎么能有蚂蚁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>

我有这样一个类:

I have a class like this:

public class UserTests extends TestCase {

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

haltonfailure =YES似乎导致构建任何一个测试失败,尽快停止,只记录第一次失败的试验。将其设置为OFF会使整个构建成功(即使测试失败消息被写入到输出)。

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.

是否有可能做到这一点?

Is it possible to do this?

推荐答案

您可以设置 failureproperty 的JUnit 任务的属性,然后用的 失败 任务:

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" />

这篇关于我怎么能有蚂蚁junit任务运行所有测试,然后停止建造其余如有测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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