如何为Surefire Maven插件指定JUnit自定义运行器?

4
假设我有一个自定义的junit类加载器,它从文本文件中读取测试数据并在运行时创建和运行测试。该运行器不使用测试类。
现在我想使用surefire maven插件运行它。也就是说,我想在pom.xml中将该运行器指定为surefire插件“execution”的参数。
我能做到吗?
3个回答

4
据我所知,在maven-surefire-plugin中没有指定Runner类的方法。但是,您应该能够创建一个单独的测试类,并使用"@RunWith(YourRunner.class)"来让它与您的自定义runner一起运行。
我认为这是因为Runner的预期用例是基于每个测试,而不是基于项目级别。您可以拥有一个项目,其中混合使用各种Runner,例如一些基于Spring,一些是并发的,一些使用JUnit3,一些使用JUnit4等。

0

0

在我的项目中,我使用插件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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接