3

假设我有一个junit自定义类加载器,它从文本文件中读取测试数据并在运行时创建和运行测试。跑步者不使用测试类。

现在我想用surefiremaven 插件运行它。也就是说,我想将 runner 指定surefirepom.xml.

我可以这样做吗?

4

3 回答 3

4

,据我所知,没有办法Runner在 maven-surefire-plugin 中指定一个类。但是,您应该能够创建一个测试类并使用它@RunWith(YourRunner.class)来让它与您的自定义运行器一起运行。

我认为这是因为Runners 的预期用例是基于每个测试的,而不是项目级别的。您可以拥有一个混合使用各种 Runner 的项目,例如,一些是基于 Spring 的,一些是并发的,一些使用 JUnit3 运行,一些使用 JUnit4 等。

于 2011-10-17T18:16:06.763 回答
0

根据您想要实现的目标,您可以使用自定义的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

于 2011-12-16T09:48:13.337 回答
0

在我的项目中,我使用插件exec-maven-plugin解决了相同的任务

我有自定义 Runner,它使用特殊参数运行 junit 测试。我用 maven 命令执行我的跑步者: 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>
于 2016-05-17T07:40:05.693 回答