英文:
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 <test-classes-jar>:<junit-jar>:<hamcrest-jar> 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?
专注分享java语言的经验与见解,让所有开发者获益!
评论