首页 文章

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

提问于
浏览
0

为什么'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

    mvn surefire:test 赢了't find any tests to execute if the sources haven'之前编译过 .

    因此,这将找不到任何执行测试:

    mvn clean
    mvn surefire:test
    

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

    mvn clean
    mvn test
    

相关问题