假设我有一个junit定制类加载器,它从一个文本文件中读取测试数据,并在运行时创建和运行测试。运行器不使用测试类。
现在我想用surefire的maven插件来运行它。也就是说,我想将运行器指定为pom.xml中surefire插件"execution“的一个参数。
我可以这样做吗?
发布于 2011-10-18 02:16:07
no .据我所知,没有办法在Runner -surefire-plugin中指定一个插件类。但是,您应该能够创建一个测试类并使用@RunWith(YourRunner.class)让它与您的自定义运行器一起运行。
我认为这是因为Runner的预期用例是基于每个测试的,而不是在项目级别。你可以有一个混合使用不同Runner的项目,例如,一些是基于Spring的,一些是并发的,一些是使用JUnit3运行的,一些是使用JUnit4运行的,等等。
发布于 2011-12-16 17:48:13
根据您想要实现的目标,您可能能够通过使用自定义RunListener来全局影响测试行为。下面是如何使用Maven Surefire插件对其进行配置:http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html#Using_custom_listeners_and_reporters
(我发布了对类似问题的相同回复,即:Globally setting a JUnit runner instead of @RunWith)
发布于 2016-05-17 15:40:06
在我的项目中,我用插件exec-maven-plugin解决了同样的任务
我有自定义的Runner,它用特殊的参数运行junit测试。我使用maven命令执行我的runner : mvn test -Dparam1=value1 -Dparam2=value2 -Dparam3=value3
在pom.xml中:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.example.domain.MyMainClass</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>https://stackoverflow.com/questions/7797742
复制相似问题