gpt4 book ai didi

maven - 使用 Maven Surefire 运行依赖 jar 中包含的 JUnit 测试

转载 作者:行者123 更新时间:2023-12-03 11:36:08 25 4
gpt4 key购买 nike

我的 maven 存储库中有一个 jar,其中包含 junit 测试,它应该在不同的项目中运行,因为它能够检查项目并测试它的某些功能。不幸的是,surefire 不会检测包含在 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>

任何帮助将被appriciated。

最佳答案

有一种方法可以从另一个 jar 在 Maven 中运行测试。
从 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可以运行的任何东西。

关于maven - 使用 Maven Surefire 运行依赖 jar 中包含的 JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10496846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com