繁体   English   中英

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

[英]Run TestNG suite from maven getting error:maven-surefire-plugin:test failed: testSuiteXmlFiles0 has null value

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

<configuration>
    <suiteXmlFiles>
        <suiteXmlFile>${testSuite}</suiteXmlFile>
    </suiteXmlFiles>
</configuration>

然后这到命令行:

mvn test -DtestSuite=myCustomSuite.xml

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

mvn test -Dgroups=myGroup

我收到此错误:

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

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

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

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

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

您还可以使用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>

出于某种原因,接受的答案对我不起作用。 我使用了类似的东西。

mvn test -Dgroups=myGroup -DtestSuite=" "

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM