我的maven存储库中有一个jar,其中包含junit测试,这些测试应该在不同的项目中运行,因为它能够检查项目并测试其中的某些功能。不幸的是,pick不会获得jar中包含的测试,就像这个Feature Request shows一样。
在功能请求中,他们建议解压jar,然后由surefire执行。
我使用maven-dependency-plugin成功地解压了jar,但是所包含的测试无论如何都不会执行。这就是我如何配置maven-dependency plugin来解压我的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>任何帮助都会得到重视。
发布于 2013-06-12 17:12:27
有一种方法可以在maven中从另一个jar运行测试。从maven-surefire-plugin版本2.15开始,你可以告诉maven扫描你的测试jar并运行它们。您不需要提取测试jar。只需向您的测试jar添加一个依赖项,然后:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<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
正如预期的那样,这适用于JUnit和Testng。可能适用于surefire可以运行的任何东西。
发布于 2013-01-29 05:48:27
(这只是重申上面来自khmarbaise的评论中的内容,但由于它没有被澄清,我认为它值得重申):
使用测试类目录,而不是outputDirectory文件夹:
<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}/test-classes
</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>发布于 2012-05-08 18:46:25
正如问题中所描述的,您需要有一个套件,它包含在您的项目中,而不是位于测试jar中。
https://stackoverflow.com/questions/10496846
复制相似问题