TestNG如果一个方法失败,如何跳过测试中的所有方法

时间:2015-07-29 08:43:26

标签: ant testng

我有一个包含两个类的testng.xml,其中每个类都包含很少的运行方法。如果第一个类中的第一个方法失败,则跳过此类中的所有其他方法,但启动此测试中的下一个类。如果一种方法失败,我需要跳过此测试中的所有内容:



<test verbose="1" name="E2E" annotations="JDK">
  <classes>
    <class name="TestNG.personalCabinet">
      <methods>
        <include name="createCabinetAndLogin" />
        <include name="loginAndFillAgreement" />
        <include name="loginCreateShopAndCheck" />
      </methods>
    </class>
    <class name="TestNG.mobileBuy">
      <methods>
        <include name="mobileScan" />
        <include name="mobileBuy" />
      </methods>
    </class>
  </classes>
</test>
&#13;
&#13;
&#13;

我用ant启动它:

&#13;
&#13;
<target name="Test.E2E" depends="compile">
  <testng outputdir="${testdir}" classpathref="all.classpath" testnames="E2E" haltonfailure="true">
    <xmlfileset dir="${basedir}" includes="testng.xml" />
    <jvmarg value="-Dfile.encoding=UTF-8" />
  </testng>
</target>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

正如您在评论中所说,dependsOnMethods就是您所寻找的。

  

您可以将测试方法b()标记为取决于测试方法a()的成功运行。如果a()失败,那么b()将被标记为SKIP,而不是FAIL。

http://beust.com/weblog/2004/08/19/dependent-test-methods/

相关问题