如何限制构建 xml 文件的测试执行时间

how to limit tests time execution from build xml file

基本上,如果某个测试花费的时间超过 2 分钟,请中止该特定测试并继续其他测试,我有这篇文章

<junit printsummary="yes" haltonfailure="no" haltonerror="no">
      <classpath>
        <pathelement path="${build.test}"/>
        <path refid="project.class.path" />
      </classpath>
      <formatter type="plain" usefile="no"/>
      <batchtest fork="yes"  haltonfailure="no" haltonerror="no" failureproperty="test.failed" todir="../src/result">
        <fileset dir="${build.test}">
          <include name="**/app/**/*Test.*"/>
          <exclude name="**/app/**/*Helper*"/>
</fileset>
      </batchtest>
    </junit>

junit ant doc 开始,您有 timeout 属性:

timeout - Cancel the individual tests if they don't finish in the given time (measured in milliseconds). Ignored if fork is disabled. When running multiple tests inside the same Java VM (see forkMode), timeout applies to the time that all tests use together, not to an individual test.

<junit fork="yes" timeout="60000" >

如果forkmode默认设置为perTest,超时值是针对每个单独的测试,但如果将forkmode指定为once,则单个JVM将运行 所有测试,该值适用于您的所有测试。