繁体   English   中英

来自TestNG.xml的TestNG方法序列

[英]TestNG method Sequence from TestNG.xml

我有两个类,我将其放在TestNG.xml上,但它没有顺序运行我的类是这样的

    public class TestBase {

    @Parameters({"paraTest"})

@Test(groups = "gp1",singleThreaded = true)
public void runMethodGP1(String a) throws InterruptedException {
        //Thread.sleep(2000);
        System.out.println("Invoked testString " + a);
    System.out.println("runMethodGP1()");
}

@Test(groups = "gp2",singleThreaded = true)
public void runMethodGP2() {
    System.out.println("runMethodGP2()");
}

@Test(groups = "gp3",singleThreaded = true)
public void runMethodGP3() {
    System.out.println("runMethodGP3()");
}

@Test(groups = "gp1",singleThreaded = true)
public void runMethod2GP1() {
    System.out.println("runMethod2GP1()");
}

@Test(groups = "gp2",singleThreaded = true)
public void runMethod2GP2() {
    System.out.println("runMethod2GP2()");
}


public class TestNGAnotationClass1 {

@Test(groups = "gp1")
public void runMethod3GP1CL1() throws InterruptedException {
    Thread.sleep(1000);
    System.out.println("runMethod3GP1CL1()");
}

@Test(groups = "gp3")
public void runMethod2GP3CL1() {
    System.out.println("runMethod2GP3CL1()");
}
}

我的TestNG.xml就是这样

  <?xml version='1.0' encoding='UTF-8' ?>
  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  <suite name="Suite1" verbose="1" order-by-instances="true" preserve-order="true">

<test name="TestNGAnotationClass2" time-out="1" preserve-order="true" annotations="JDK">
    <parameter name="paraTest" value="Test">
    </parameter>
    <classes>
        <class name="excelfilereadapachepoi.TestBase">
        </class>
        <class name="excelfilereadapachepoi.TestNGAnotationClass1">
        </class>
    </classes>
  </test>
</suite>

输出:

runMethod2GP1()runMethod2GP2()调用了testString测试runMethodGP1()runMethodGP2()runMethodGP3()runMethod2GP3CL1()

但是应该是这样

调用了testString测试runMethodGP1()runMethodGP2()runMethod2GP1()runMethod2GP2()runMethodGP3()runMethod2GP3CL1()

谁能告诉我我哪里错了。

我正在使用TestNG 6.8.1

如果我正确地理解了您的问题,因为您想按指定的顺序运行测试,则可以使用TestNG IMethodInterceptor。 查看有关如何利用它们的http://beust.com/weblog2/archives/000479.html

要么

使用dependsOnMethods和/或dependsOnGroups:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM