JUnit:NoClassDefFoundError:org / junit / runner / manipulation / Filter

时间:2015-11-04 12:04:33

标签: java junit

当我尝试运行某些单元测试时,会引发以下错误:

message1=changes.split(" ")
if message1[0] == 'D'
changes="deleted"

我必须提到junit-4.11.jar已添加到项目构建路径中。有什么想法吗?

4 个答案:

答案 0 :(得分:26)

即使我遇到同样的问题,请尝试以下步骤 -

  1. 在Package Explorer中右键单击该项目,然后单击Properties。
  2. 单击“库”选项卡。
  3. 单击“添加库”按钮。
  4. 选择JUnit,然后单击“下一步”。
  5. 选择JUnit 4(这就是我正在使用的)。
  6. 点击完成。
  7. 现在右键单击包含单元测试的文件,然后选择属性。
  8. 在“运行/调试”设置下,从该文件的“启动配置”中删除所有条目。点击确定。
  9. 希望你现在能够运行测试。

答案 1 :(得分:5)

此错误可能是通过将JUnit库添加到Modulepath而不是Classpath引起的。

在Eclipse最左侧的面板“ Package Explorer”中,右键单击您的项目,然后转到属性,然后转到“ Java Build Path”。单击“ Classpath”,而不是“ Modulepath”,单击“ Add Library ...”,然后单击Junit。 / p>

enter image description here

enter image description here

答案 2 :(得分:0)

就我而言,错误具有相同的堆栈跟踪(以 java.lang.Class.forName0(Native Method) 结尾),但错误消息不同:

java.lang.VerifyError: (class: org/junit/runner/manipulation/Alphanumeric, method: create signature: (Lorg/junit/runner/manipulation/Ordering$Context;)Lorg/junit/runner/manipulation/Ordering;) Wrong return type in function

原因原来是我将JUnit从4.11升级到4.13.1,因为GitHub的“dependabot”建议这样做,在我的一些公共项目中,甚至创建了准备接受的合并请求,我想“当然,为什么不呢,可能会出什么问题?”结论:不要相信GitHub的dependabot。

答案 3 :(得分:0)

看起来这是 eclipse 中的一个缺陷,请更新 eclipse 或基于 eclipse 的编辑器来解决这个问题。

请参阅此处了解更多详情 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=525844