使用Maven Surefire运行依赖jar中包含的JUnit测试 [英] Run JUnit Tests contained in dependency jar using Maven Surefire

查看:229
本文介绍了使用Maven Surefire运行依赖jar中包含的JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的maven存储库中有一个包含junit测试的jar,它应该在不同的项目中运行,因为它能够检查项目并测试它的某些功能。不幸的是,surefire不会接收jar中包含的测试,因为功能请求显示

I have a jar in my maven repository that contains junit tests, which should be run in different projects, because it is able to inspect the project and test for certain features of it. Unforunately surefire doesn't pick up tests that are contained in a jar, as this Feature Request shows.

在功能请求中,他们建议解压jar然后通过surefire执行。

In the feature request they propose to unpack the jar to be then executed by surefire.

我成功解压缩jar使用了maven-dependency-plugin,但无论如何都不会执行包含的测试。这就是我如何配置maven-dependency-plugin以解压我的jar:

I successfully unpacked the jar using the maven-dependency-plugin, but the contained tests are not executed anyway. This is how I configured the maven-dependency-plugin to unpack my jar:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>de.mwx.test</groupId>
                        <artifactId>selenium-test-base</artifactId>
                        <version>0.1</version>
                        <overWrite>true</overWrite>
                          <outputDirectory>
                              ${project.build.directory}/classes
                          </outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

任何帮助都是适当的。

推荐答案

有一种从另一个jar在maven中运行测试的新方法。来自maven-surefire-plugin版本2.15的
你可以告诉maven扫描你的测试罐进行测试并运行它们。
您不需要提取测试jar。
只需在测试jar中添加一个依赖项,然后:

There is a new way of running a test in maven from another jar. from maven-surefire-plugin version 2.15 you can tell maven to scan your test jars for tests and run them. You don't need to extract the tests jar. Just add a dependency to your test jar and:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.15</version>
        <configuration>
            <dependenciesToScan>
                <dependency>test.jar.group:test.jar.artifact.id</dependency>
            </dependenciesToScan>
        </configuration>
    </plugin>

https://gist.github.com/aslakknutsen/4520226
https://issues.apache.org/jira/browse/SUREFIRE-569

这篇关于使用Maven Surefire运行依赖jar中包含的JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆