Java TestNG.xml中的TestNG方法序列
我有两个类,我把它放在TestNG.xml上,但它不是按顺序运行的,我的类是这样的Java TestNG.xml中的TestNG方法序列,java,unit-testing,selenium-webdriver,testng,Java,Unit Testing,Selenium Webdriver,Testng,我有两个类,我把它放在TestNG.xml上,但它不是按顺序运行的,我的类是这样的 public class TestBase { @Parameters({"paraTest"}) @Test(groups = "gp1",singleThreaded = true) public void runMethodGP1(String a) throws InterruptedException { //Thread.sleep(2000); S
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()");
}
}
<?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>
我的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()");
}
}
<?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()
调用的测试字符串测试
runMethodGP1()
runMethodGP2()
runMethodGP3()
runMethod2GP3CL1()
但应该是这样的
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()");
}
}
<?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>
调用的测试字符串测试
runMethodGP1()
runMethodGP2()
runMethod2GP1()
runMethod2GP2()
runMethodGP3()
runMethod2GP3CL1()
谁能告诉我哪里错了
我正在使用TestNG 6.8.1如果我正确理解您的问题,您希望按指定顺序运行测试,则可以使用TestNG IMethodInterceptor。看看如何利用它们 或
使用dependsOnMethods和/或dependsongroup:TestNG不保证测试顺序,这是理所当然的。如果您希望测试按特定顺序运行,请使用
dependsOn{Methods,Groups}
和/或priority
@fge谢谢您的评论。我在@Test中使用priority来克服这个条件,但我想知道我是否可以只使用TestNG.xml设置来克服这个条件,或者我还需要配置@Test(priority=“some Integer value”),因为在TestNG.xml文件中已经保留order=“true”属性。我在@Test中使用priority来克服此条件,但我想知道我是否可以只使用TestNG.xml设置来克服此条件,或者我还需要配置@Test(priority=“some Integer value”),因为TestNG.xml文件中已经有preserve order=“true”属性。