首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JUnit5 ConsoleLauncher NoClassDefFoundError

JUnit5 ConsoleLauncher NoClassDefFoundError
EN

Stack Overflow用户
提问于 2019-01-28 20:23:05
回答 1查看 503关注 0票数 0

我的测试文件使用了Commons库:

代码语言:javascript
复制
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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54409727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档