【问题标题】:How to make property optional in Maven with Surefire plugin如何使用 Surefire 插件在 Maven 中使属性成为可选
【发布时间】:2020-12-23 11:07:37
【问题描述】:

我正在使用 Surefire 插件运行 TestNG 套件,我需要运行来自 suite.xml 的完整套件或特定测试。同样,我使用testnames 属性提供测试名称,它与testnames 一起工作正常 但是当我在没有testnames 参数的情况下运行时,它会抛出异常The test(s) <[]> cannot be found.

我想知道有什么可以让它成为可选的吗?

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
          </suiteXmlFiles>          
          <properties>
            <property>
              <name>testnames</name>
              <value>${testnames}</value>
              
            </property>
          </properties>
          <useSystemClassLoader>false</useSystemClassLoader>
          <testFailureIgnore>false</testFailureIgnore> 
          </configuration>
        </plugin>
        <plugin>

我正在使用的 Maven 命令:

mvn test -DcfgFile=abc.cfg  -DsuiteXmlFile=Suite.xml -Dtestnames=test1  -f pom.xml -U

我希望它也能正常工作:

mvn test -DcfgFile=abc.cfg  -DsuiteXmlFile=Suite.xml -f pom.xml -U

提前致谢。

【问题讨论】:

    标签: java maven testng


    【解决方案1】:

    您不能将属性设为可选。但是您可以创建一个DummyTestThatDoesNothing 并将其定义为您的 POM 中的默认值:

      <properties>
        <testnames>DummyTestThatDoesNothing</testnames>
      </properties>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 2021-11-17
      • 2014-01-07
      • 2018-04-06
      • 2018-05-26
      • 2018-12-20
      相关资源
      最近更新 更多