【问题标题】:Why does 'mvn test' work for me but not 'mvn surefire:test' when using TestNG?为什么在使用 TestNG 时“mvn test”对我有用,但对“maven surefire:test”不起作用?
【发布时间】:2013-10-29 20:28:30
【问题描述】:

为什么在使用 TestNG 时“mvn test”对我有用,但对“mvn surefire:test”不起作用?这很有趣,因为套件 xml 文件的位置是通过 surefire 插件配置的,但它仅在我使用常规 Maven“测试”目标执行时运行。当我使用'mvn surefire:test'时,当文件物理上似乎存在于预期位置时,就好像资源(或src/test/resources/testng.xml)文件对测试执行者不可见:/target /test-classes/testng.xml .

这是我的配置。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire.version}</version>
    <configuration>
        <includes>
      <include>Tests/**/*.java</include>
        </includes>
        <suiteXmlFiles>
            <suiteXmlFile>
                 ${project.build.testOutputDirectory}/${testng.suitexmlfile}
                    </suiteXmlFile>
        </suiteXmlFiles>
        <configuration>
            <systemPropertyVariables>
                <build-name>${testng.buildname}</build-name>
                <testenv>${testng.testenv}</testenv>
            </systemPropertyVariables>
            <groups>${testng.groups}</groups>
        </configuration>
    </configuration>
</plugin>

【问题讨论】:

    标签: maven unit-testing testng maven-surefire-plugin


    【解决方案1】:

    mvn surefire:test 如果之前没有编译过源代码,将找不到任何要执行的测试。

    因此这不会找到任何要执行的测试:

    mvn clean
    mvn surefire:test
    

    但这应该可以工作(因为 mvn test 绑定到 maven 生命周期并在执行测试之前编译源代码):

    mvn clean
    mvn test
    

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 1970-01-01
      • 2019-05-13
      • 2015-08-01
      • 2010-10-08
      • 2016-02-27
      • 2019-01-13
      • 2015-09-07
      • 1970-01-01
      相关资源
      最近更新 更多