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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33521436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:43:51  来源:igfitidea点击:

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

javajunit

提问by lucian.marcuta

When I try to run some unit tests, the following error is raised:

当我尝试运行一些单元测试时,出现以下错误:

java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:320)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:310)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:305)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:283)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:207)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:191)

I have to mention that junit-4.11.jar is added to project build path. Any ideas?

不得不提的是,junit-4.11.jar 添加到项目构建路径中。有任何想法吗?

EDIT:I (Gábor Lipták) have read the other question this question supposed to be a duplicate of. This is NOT a duplicate.If someone has Gradle Buildship as build plugin in Eclipse, exactly this error is thrown, if you mistakenly put your test class in main/resorcesinstead of test/resources. Buildship seems to take care of test vs. compile classpath, when it comes to generate a run configuration. See the following snippets of my .classpathfile below as evidence:

编辑:我(Gábor Lipták)已经阅读了另一个问题,这个问题应该是重复的。这不是重复的。如果有人在 Eclipse 中使用 Gradle Buildship 作为构建插件,如果您错误地将测试类放在main/resorces而不是test/resources. 在生成运行配置时,Buildship 似乎负责测试与编译类路径。请参阅下面我的.classpath文件的以下片段作为证据:

<classpathentry kind="src" output="bin/main" path="src/main/resources">
    <attributes>
        <attribute name="gradle_scope" value="main"/>
        <attribute name="gradle_used_by_scope" value="main,test"/>
    </attributes>
</classpathentry>

<classpathentry kind="src" output="bin/test" path="src/test/resources">
    <attributes>
        <attribute name="gradle_scope" value="test"/>
        <attribute name="gradle_used_by_scope" value="test"/>
    </attributes>
</classpathentry>

回答by mmwaikar

Even I was facing the same issue, so try the below steps -

即使我也面临同样的问题,所以请尝试以下步骤 -

  1. Right click the project in Package Explorer, and click Properties.
  2. Click the Libraries tab.
  3. Click the Add library button.
  4. Select JUnit and click Next.
  5. Select JUnit 4 (that's what I am using).
  6. Click finish.
  7. Now right click the file containing unit tests and select Properties.
  8. Under the Run/Debug settings, remove any entries from the Launch Configurations for that file. Hit ok.
  1. 在包资源管理器中右键单击项目,然后单击属性。
  2. 单击库选项卡。
  3. 单击添加库按钮。
  4. 选择 JUnit 并单击下一步。
  5. 选择 JUnit 4(这就是我正在使用的)。
  6. 单击完成。
  7. 现在右键单击包含单元测试的文件并选择属性。
  8. 在运行/调试设置下,从该文件的启动配置中删除任何条目。打好。

Hopefully you'll be able to run the tests now.

希望您现在能够运行测试。