TestNG 方法序列来自 TestNG.xml [英] TestNG method Sequence from TestNG.xml
问题描述
我有两个类,我把它放在 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()");
}
}
我的TestNG.xml就是这样
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>
输出:
runMethod2GP1()运行方法2GP2()调用 testString 测试运行方法GP1()运行方法GP2()运行方法GP3()runMethod2GP3CL1()
runMethod2GP1() runMethod2GP2() Invoked testString Test runMethodGP1() runMethodGP2() runMethodGP3() runMethod2GP3CL1()
但应该是这样
调用 testString 测试运行方法GP1()运行方法GP2()运行方法2GP1()运行方法2GP2()运行方法GP3()runMethod2GP3CL1()
Invoked testString Test runMethodGP1() runMethodGP2() runMethod2GP1() runMethod2GP2() runMethodGP3() runMethod2GP3CL1()
任何人都可以告诉我我错在哪里.
Can any body tell me where I am wrong.
我使用的是 TestNG 6.8.1
I am using TestNG 6.8.1
推荐答案
如果我正确理解您的问题,因为您希望以指定的顺序运行测试,则可以使用 TestNG IMethodInterceptor.看看 http://beust.com/weblog2/archives/000479.html了解如何利用它们.
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.
或
使用dependsOnMethods 和/或dependsOnGroups:
Use dependsOnMethods and/or dependsOnGroups:
这篇关于TestNG 方法序列来自 TestNG.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!