可以使用Maven为测试类创建一个包含测试依赖的JAR吗?

huangapple 未分类评论43阅读模式
英文:

Is it possible to create a jar for test classes that contains the test dependencies using maven?

问题

我已经成功创建了一个包含类文件及其依赖的 JAR 文件,以及一个单独包含 Java 系统测试类的 JAR 文件。我试图使用 JUnit 从命令行执行这些测试类,命令如下:

java -cp <test-classes-jar>:<junit-jar>:<hamcrest-jar> org.junit.runner.JUnitCore TestClass

然而,由于测试中使用了 Google Truth,导致测试用例无法执行并出现了“类未找到”错误。我知道我可以通过将 Google Truth JAR 文件添加到类路径中来解决此问题,但我想避免这样做。

是否有一种方法可以生成一个单独的 JAR 文件,其中包含测试类及其依赖项?

英文:

I've managed to create a jar containing the class files with dependencies and a separate jar containing the test classes for a java system. I'm trying to execute the test classes from the command line using JUnit, like so:

java -cp &lt;test-classes-jar&gt;:&lt;junit-jar&gt;:&lt;hamcrest-jar&gt; org.junit.runner.JUnitCore TestClass

However, the test cases won't execute due to the tests using google truth, resulting in a class not found error. I know I can work around this by appending the google truth jar onto the class path, but I'd like to avoid this.

Is there a way to generate a single jar which contains the test classes and their dependencies?

huangapple
  • 本文由 发表于 2020年4月3日 22:19:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/61013929.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定