从maven运行TestNG套件获取错误:maven-surefire-plugin:test failed:testSuiteXmlFiles0具有null值

zmo*_*ris 5 java testng maven

我在这里看到很多关于使用Maven surefire插件运行TestNG套件的帖子.示例说要将其添加到pom中:

<configuration>
    <suiteXmlFiles>
        <suiteXmlFile>${testSuite}</suiteXmlFile>
    </suiteXmlFiles>
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后这到命令行:

mvn test -DtestSuite=myCustomSuite.xml
Run Code Online (Sandbox Code Playgroud)

我的问题是它将你绑定到使用TestNG套件...例如,如果我想运行这样的组:

mvn test -Dgroups=myGroup
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

maven-surefire-plugin:2.18.1:测试失败:testSuiteXmlFiles0具有空值

我希望能够从命令行运行套件路径或组.

juh*_*err 8

您可以:不使用属性的surefire配置,而是:

  1. 删除surefire配置并替换mvn test -DtestSuite=myCustomSuite.xmlmvn test -Dsurefire.suiteXmlFiles=myCustomSuite.xml.请参阅Surefire文档
  2. 继续使用mvn test -Dgroups=myGroup.

由于将删除surefire配置testSuiteXmlFiles0 has null value,该-Dgroup选项将不会出现错误.

您还可以使用maven配置文件,它将配置surefire插件,具体取决于您传递给maven的属性.

<profiles>
  <profile>
    <id>suite</id>
    <activation>
      <property>
        <name>testSuite</name>
      </property>
    </activation>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>${testSuite}</suiteXmlFile>
        </suiteXmlFiles>
      </configuration>
    </plugin>
  </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)