简体   繁体   中英

TestNG method Sequence from TestNG.xml

I have Two class and I put this on TestNG.xml but it does not run sequentially My classes are like that

    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()");
}
}

My TestNG.xml is like that

  <?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>

Output:

runMethod2GP1() runMethod2GP2() Invoked testString Test runMethodGP1() runMethodGP2() runMethodGP3() runMethod2GP3CL1()

But it should be like that

Invoked testString Test runMethodGP1() runMethodGP2() runMethod2GP1() runMethod2GP2() runMethodGP3() runMethod2GP3CL1()

Can any body tell me where I am wrong.

I am using TestNG 6.8.1

If I understand your question correctly in that you want to run tests in a specified order, TestNG IMethodInterceptor can be used. Take a look at http://beust.com/weblog2/archives/000479.html on how to leverage them.

OR

Use dependsOnMethods and/or dependsOnGroups:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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