【问题标题】:How to run a multiple class with multiple testng test in sequential order using maven on java如何在java上使用maven按顺序运行具有多个testng测试的多个类
【发布时间】:2016-01-22 23:44:25
【问题描述】:

在 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(priority=2) 都失败了。

如何让我的测试根据每个类的优先级顺序执行,并且类应该一个一个地执行?

【问题讨论】:

    标签: java android maven testng appium


    【解决方案1】:

    您可以使用dependOnMethod 测试功能。这样做:

    @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 {
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-25
      • 2019-12-25
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多