为什么'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 回答
mvn surefire:test 赢了't find any tests to execute if the sources haven'之前编译过 .
因此,这将找不到任何执行测试:
但是这应该工作(因为mvn clean绑定到maven生命周期并在执行测试之前编译源代码):