簡體   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