我的测试文件使用了Commons库:
import org.apache.commons.io.FileUtils;
...
@Test
public void testExampleEvalOutput_dataset() throws IOException {
File file1 = FileUtils.getFile(pathToProject + pathToExampleResults + "exampleEvalOutput_dataset.csv");
File file2 = FileUtils.getFile(pathToProject + pathToYourResults + "exampleEvalOutput_dataset.csv");
assertEquals(true, FileUtils.contentEquals(file1, file2));
}当我从Eclipse运行时,测试可以工作。
试图从命令行运行。编译测试文件:
$ mkdir out
Commons与JUnit JUnit ConsoleLauncher jar一起位于ConsoleLauncher目录中。
$ javac -d out -cp "lib/*" path/to/ExampleEvalTests.java
汇编作品。
但是,在运行时没有获取库:
$ java -jar lib/junit-platform-console-standalone-1.3.2.jar -cp lib:out/ --scan-class-path
JUnit Vintage:ExampleEvalTests:testExampleEvalOutput_dataset
MethodSource [className = 'org.company.test.ExampleEvalTests', methodName = 'testExampleEvalOutput_dataset', methodParameterTypes = '']
=> java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
org.company.test.ExampleEvalTests.testExampleEvalOutput_dataset(ExampleEvalTests.java:27)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:564)
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[...]目录结构:
lib org company test out
如何让out中的可执行文件获取lib
发布于 2019-01-29 21:47:35
基于@Sormuras注释,添加用于类路径工作的特定jar。但是,如果使用了许多依赖项,这似乎不是一个理想的解决方案:
$ java -jar lib/junit-platform-console-standalone-1.3.2.jar -cp lib/commons-io-2.6.jar:out --scan-class-path
https://stackoverflow.com/questions/54409727
复制相似问题