如何在java上使用maven以顺序运行带有多个testng测试的多个类

如何在java上使用maven以顺序运行带有多个testng测试的多个类,java,android,maven,testng,appium,Java,Android,Maven,Testng,Appium,在pom.xml中 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <suiteXmlFiles>

在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时,首先执行所有类文件中的所有@BeforeClass,然后逐个执行所有类中的@Test(priority=1)方法

由于上述情况,来自所有类文件的my@Test(priority=2)失败


如何使我的测试根据优先级按顺序执行?每个类和类都应该逐个执行?

您可以使用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 {
}
@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 {
}
@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 {
}