为什么'mvn test'对我有用,但在使用TestNG时没有'mvn surefire:test'?

时间:2013-10-29 20:28:30

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

为什么'mvn test'对我有用,但在使用TestNG时没有'mvn surefire:test'?它很有趣,因为套件xml文件的位置是通过surefire插件配置的,但它只在我执行常规Maven'test'目标时运行。当我使用'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>

1 个答案:

答案 0 :(得分:0)

mvn surefire:test 如果以前没有编译过源,将无法找到任何要执行的测试。

因此,这将无法执行任何测试:

mvn clean
mvn surefire:test

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

mvn clean
mvn test
相关问题