TestNg-通过mvn命令行排除一个类(testrunner)

时间:2019-12-13 20:05:28

标签: maven cucumber testng

说明:

作为用户,我想在运行mvn clean test时排除一个类(Test Runner)

伪代码:

~ mvn clean verify -Dexclude=SampleTest

我如何运行我的构建:

~ mvn clean verify;这会触发以testng.xml

为目标的surefire插件

XML:(TESTNG)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automated UI Tests">
    <test name = "Cucumber Test" verbose="2">
        <classes>
            <class name="com.testrunners.SampleTest"/>
            <class name="com.testrunners.Sample2Test"/>
            <class name="com.testrunners.Sample3Test"/>
        </classes>
    </test>
</suite>

我尝试对(@Test groups=sample进行分组,但这似乎不适用于我的情况。

不确定是否重要,但这是我的测试跑步者的摘要。

package com.testrunners;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features =  {
                "src/test/java/com/features/",
        },
        glue = {
                "com.stepdefinitions"
        },
        monochrome = true,
        tags =  {
                "@smoke"
        },
        plugin = {"pretty",
                "html:target/cucumber/sample",
                "json:target/cucumber-report/sample/cucumber.json",
                "json:target/sample/cucumber.json",
                "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter: target/sample/report.html"}
)

public class SampleTest extends AbstractTestNGCucumberTests {
}

任何帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

从您的问题来看,在我看来您正在使用maven故障安全插件来执行。

可以使用2种方法:

来自Maven故障保护插件:

您可以在POM.xml中使用excludes属性。请查看配置以完成此操作。来自Maven故障安全官方文档插件的参考。

1   <project>
2     [...]
3     <build>
4       <plugins>
5         <plugin>
6           <groupId>org.apache.maven.plugins</groupId>
7           <artifactId>maven-failsafe-plugin</artifactId>
8           <version>3.0.0-M4</version>
9           <configuration>
10            <excludes>
11              <exclude>**/CircleIT.java</exclude>
12              <exclude>**/SquareIT.java</exclude>
13            </excludes>
14          </configuration>
15        </plugin>
16      </plugins>
17    </build>
18    [...]
19  </project>

您可以在此处查看此内容:

https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

这样,您可以使用以下方式运行测试用例

mvn clean verify

来自TestNG:

不能直接排除测试classesclass;但是,您可以通过组排除类:

@Test(groups = { "ClassTest1" })
public class Test1 {

  public void testMethod1() {
  }

  public void testMethod2() {
  }

}

然后,您将定义testng.xml:

<suite>
  <test>
    <groups>
      <run>
        <exclude name="ClassTest1"/>
      </run>
    </groups>
    <classes>
      <class name="Test1">
    </classes>
  </test>