如何让Ant JUnit任务运行所有测试,然后在任何测试失败时停止构建的其余部分
我通过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"/>
<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" />