1

为什么在使用 TestNG 时“mvn test”对我有用,但对“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>
4

1 回答 1

1

mvn surefire:test won't find any tests to execute if the sources haven't been compiled before.

Therefore this won't find any tests to execute:

mvn clean
mvn surefire:test

This however should work (because mvn test is bound to the maven lifecycle and compiles the sources before executing the tests):

mvn clean
mvn test
于 2013-11-14T10:16:43.313 回答