【问题标题】:How can I have the Ant JUnit task run all tests and then stop the rest of the build if any test has failed如何让 Ant JUnit 任务运行所有测试,然后在任何测试失败时停止其余的构建
【发布时间】:2011-05-01 14:43:18
【问题描述】:

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

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

可以这样做吗?

【问题讨论】:

    标签: ant junit junit3


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-24
      • 2015-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 2011-02-09
      相关资源
      最近更新 更多