首页 > 解决方案 > 使用组和 dataProvider 值运行时跳过 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

标签: maventestng

解决方案


-Dgroups=sanity在 Maven 命令行上,除了定义要在项目的 POM 中使用的属性外,什么都不做。

要定义要测试的组,您必须相应地为 Surefire 插件声明它们

  <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 ...没有必要,因为调用 Maven 的阶段无论如何都会install通过test阶段。


推荐阅读