我想知道是否有人知道如何在同一次运行中重新运行失败的 Junit 测试。例如,运行测试 1-5 并在运行测试 6 时全部通过,但第一次失败。然后它会自动再次运行,然后再继续测试 7。我正在使用运行我所有测试的 ant 脚本。 如果有帮助,测试将在 Hudson 盒子上运行。我读到过能够选择失败的测试并将它们放在一个新文件中,在第二次运行套装时运行它们,但这并不是我真正想要的。
任何正确方向的帮助或指示都会有所帮助。谢谢。
<!-- ============================= -->
<!-- target: test-regression-all -->
<!-- ============================= -->
<!--
<target name="test-regression-all" description="Runs all tests tagged as regression" depends="compile">
<mkdir dir="${target.reports.dir}"/>
<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes"
failureproperty="junit.failure" errorproperty="junit.error" showoutput="true">
<formatter type="xml"/>
<classpath>
<pathelement location="${target.build.classes.dir}"/>
<path refid="classpath"/>
</classpath>
<batchtest todir="${target.reports.dir}">
<fileset dir="${src.dir}">
<include name="emailMarketing/AssetLibrary/*.java" />
<include name="emailMarketing/attributes/*.java" />
<include name="emailMarketing/contacts/*.java" />
<include name="emailMarketing/DomainKeys/*.java" />
<include name="emailMarketing/lists/*.java" />
<include name="emailMarketing/messages/*.java" />
<include name="emailMarketing/Segments/*.java" />
<include name="emailMarketing/UploadContact/*.java" />
<exclude name="emailMarketing/lists/ListArchive.java"/>
<exclude name="emailMarketing/messages/MessageCreation.java" />
</fileset>
</batchtest>
<jvmarg value="-Duser=${user}"/>
<jvmarg value="-Dpw=${pw}"/>
<jvmarg value="-Dbrowser=${browser}"/>
<jvmarg value="-Dserver=${server}"/>
<jvmarg value="-Dopen=${open}"/>
<jvmarg value="-DtestType=regression"/>
</junit>
<junitreport todir="${target.reports.dir}">
<fileset dir="${target.reports.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${target.reports.dir}"/>
</junitreport>
<fail if="junit.failure" message="Test(s) failed. See reports!"/>
<fail if="junit.error" message="Test(s) errored. See reports!"/>
</target>
最佳答案
查看 Ant Retry 任务。
<target name="myTest1">
<mkdir dir="${junit.output.dir}" />
<retry retrycount="3">
<junit haltonerror="yes" haltonfailure="yes"
fork="no" printsummary="withOutAndErr"
showoutput="true" tempdir="c:/tmp">
<formatter type="xml" />
<test name="MyPackage.myTest1" todir="${junit.output.dir}" />
<classpath refid="Libs.classpath" />
<formatter type="brief" usefile="false"/>
</junit>
</retry>
</target>
关于ant - Junit/Ant 重新运行失败的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7730820/