使用组和dataProvider值运行时跳过了TestNG测试

时间:2019-04-09 10:27:26

标签: maven testng

使用以下代码跳过测试

@Test(groups = { "sanity", "prod" }, dataProviderClass = ReqRespDataProvider.class, dataProvider = "sampleTestData")
public void sampleMethodTest(Map<DataType, String> map){

}

运行

mvn clean install test -Dgroups=sanity

结果:

Running TestSuite
Tests run: 2, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 5.426 sec

2 个答案:

答案 0 :(得分:0)

Maven命令行上的

-Dgroups=sanity除了定义要在项目的POM中使用的属性外,什么也没有做。

要定义要测试的组,您必须declare them for the Surefire Plugin accordingly

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
      <groups>${groups}</groups>
    </configuration>
  </plugin>

顺便说一句,... install test ...是不必要的,因为invoking Maven's install phase passes the test phase anyway

答案 1 :(得分:0)

找到了解决方案。 使用groups标签运行测试时,@ BeforeSuite方法被跳过了。我已经更改了@BeforeSuite(alwaysRun = true),并在运行中拾取了所有带有组标记的测试。

相关问题