【问题标题】:Run TestNG suite from maven getting error:maven-surefire-plugin:test failed: testSuiteXmlFiles0 has null value从 maven 运行 TestNG 套件出现错误:maven-surefire-plugin:test failed: testSuiteXmlFiles0 has null value
【发布时间】:2015-09-09 20:21:31
【问题描述】:

我在这里看到很多关于使用 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:test failed: testSuiteXmlFiles0 has null value

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

【问题讨论】:

    标签: java maven testng


    【解决方案1】:

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

    mvn test -Dgroups=myGroup -DtestSuite=" "
    

    【讨论】:

      【解决方案2】:

      您可以:

      1. 删除surefire配置并将mvn test -DtestSuite=myCustomSuite.xml替换为mvn test -Dsurefire.suiteXmlFiles=myCustomSuite.xml。见Surefire documentation
      2. 继续使用mvn test -Dgroups=myGroup

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

      您还可以使用 maven 配置文件,该配置文件将根据您传递给 maven 的属性配置 surefire 插件。

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

      【讨论】:

      • 你能举个例子吗?
      • 完成,但我找到了更好的解决方案
      • 我刚试过这个,但在使用 -Dgroups 时不起作用...请在给出答案之前阅读问题。
      • 您是否也删除了您的安全配置?
      • 好的,这行得通...谢谢。我会接受你的回答并点赞。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多