Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让Ant JUnit任务运行所有测试,然后在任何测试失败时停止构建的其余部分_Ant_Junit_Junit3 - Fatal编程技术网

如何让Ant JUnit任务运行所有测试,然后在任何测试失败时停止构建的其余部分

如何让Ant JUnit任务运行所有测试,然后在任何测试失败时停止构建的其余部分,ant,junit,junit3,Ant,Junit,Junit3,我通过Ant使用如下目标运行JUnit: <target name="junit" depends="compile"> <mkdir dir="${report.dir}"/> <junit printsummary="yes" haltonfailure="yes" showoutput="yes" > <classpath> <path refid="classpath"/>

我通过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”将导致整个构建成功(即使测试失败消息被写入输出)

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

可以这样做吗?

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


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