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

TestNG test skipped while running with groups and dataProvider values

使用以下代码跳过测试,

@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
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.

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