ClassNotFoundException: junit.framework.TestCase cannot be found by org.eclipse.xtext.junit_2.4.3.v201309030823

时光总嘲笑我的痴心妄想 提交于 2019-12-03 23:56:17
A Paul

Two points

First

Check your Project Properties->Java Build Path->Libraries (tab). JUnit should be there although this usually will show up in the build.

Check you Project's Run Configurations->JUnit->Classpath (tab). JUnit should be under User Entries for your project.

Second

Check you have below plugins

org.eclipse.xtext.xbase.junit
org.junit (3.8.2)
org.junit (4.8.2)

[EDIT] This got me on the right track. To fix the error make sure you have org.junit 3.8 in the target platform!

Explanation: The error above means that Eclipse itself couldn't start. It seems that the JUnit runner has a dependency on JUnit 3.8. It won't be used but without it, the whole platform can't be initialized.

You can see whether you have the same problem by looking at the stack trace: Does it contain RemotePluginTestRunner.main?

To fix the error, add the org.junit 3.8 bundle to your target platform.

Create a class with below code in your project-

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class TestJunitLib {

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void test() {
    fail("Not yet implemented");
}

}

On saving if eclipse shows compiler errors. Press Ctrl + 1 ( Quick Fix ) and select one of the below-

a) Add jUnit 4 library to buildpath b) Fix project setup

If a does not appear your eclipse installation is missing jUnit 4 plugin. In that case google up on how to install jUnit in eclipse.

You may have have unresolved issues in your pom.xml file. Open the problems view solve accordingly. Then ideally you will be able to run the test cases successfully without encountering the classnotfoundexception.

Two possible places to check for more details:

  1. Decompile the jar you mentioned (jar tvf or javap -classpath and specify the JAR), and check for its dependecies
  2. Check eclipse.ini for some initialization variables that could possibly be fixed.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!