maven surefire testng 执行不工作

maven surfire testng execution not working

我在设置项目以使用 testng 时遇到问题。 背景是我想用 maven 命令行执行我的 test.xml 。 我在 pom.xml:

的构建部分中使用了这个插件
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>3.0.0-M5</version>
   <configuration>
     <suiteXmlFiles>
        <suiteXmlFile>test.xml</suiteXmlFile>
     </suiteXmlFiles>
   </configuration>
</plugin>

但是...当我打电话给mvn clean test -DxmlSuiteFile=test.xml 我的所有单元测试都已执行,但 test.xml 未受影响。

当我将 surefire 的版本更改为 2.22.2 时,一切正常。 但我收到消息:testSuiteXmlFiles0 has null value 仅当 运行ning mvn test

我很困惑如何使用 surefire 3.0.0-M5 将其设置为 运行?

-DxmlSuiteFile=test.xml 如果已在 pom.xml 中定义,则不需要 -DxmlSuiteFile=test.xml

尝试明确定义 surefire testNG 提供程序:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>test.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-testng</artifactId>
            <version>3.0.0-M5</version>
        </dependency>
    </dependencies>
</plugin>

test.xml 文件应该在项目根目录中。


另请参阅: https://maven.apache.org/surefire/maven-surefire-plugin/examples/providers.html