Surefire 通常会根据项目类路径中存在的 TestNG/JUnit 版本自动选择要使用的测试框架提供程序。在某些情况下,可能需要手动覆盖这样的选择。这可以通过将所需的提供程序作为依赖项添加到 surefire-plugin 来完成。
以下示例显示如何强制 junit 4.7 提供程序:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.9</version>
</dependency>
</dependencies>
</plugin>
[...]与surefire 一起提供的提供程序是surefire-junit3、surefire-junit4、surefire-junit47 和surefire-testng。请注意,强制提供者仍然需要在您的项目类路径上正确设置测试框架。
您还可以指定多个提供程序作为依赖项,它们都将运行并生成一个通用报告。这对于外部提供者来说可能特别方便,因为很少有用于组合包含的提供者的用例。