在pom.xml中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testing.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
在testing.xml中
<suite name="Suite1" verbose="1">
<test name="Regression1" parallel="false" preserve-order="true">
<packages>
<package name="apps.sample.test1.*" />
<package name="apps.sample.test2.*" />
</packages>
<classes>
<class name="apps.sample.test1.Test1.java" />
<class name="apps.sample.test1.Test2.java" />
</classes>
</test>
</suite>
apps.sample.test1。*包含以下内容 1. apps.sample.test1.Test1.java
@BeforeClass
public void test1(Method method) throws Exception {
}
@Test(priority=1)
public void test2(Method method) throws Exception {
}
@Test(priority=2)
public void test3(Method method) throws Exception {
}
@Test(priority=3)
public void test4(Method method) throws Exception {
}
当我运行testing.xml时,所有Class文件中的所有@BeforeClass首先被执行,然后@Test(priority = 1)方法从所有类执行,逐个执行。
由于上述情况,我所有类文件的@Test(优先级= 2)都失败了。
如何根据每个类的优先级按顺序执行我的测试,并且应该逐个执行类?
答案 0 :(得分:1)
您可以使用dependOnMethod testng功能。这样做:
@Test
public void test2(Method method) throws Exception {
}
@Test(dependsOnMethods = "test2")
public void test3(Method method) throws Exception {
}
@Test(dependsOnMethods = "test3")
public void test4(Method method) throws Exception {
}