Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm puzzled by this error:

java.lang.NoClassDefFoundError: junit/framework/TestCase
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:638)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
    at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
...
Caused by: java.lang.ClassNotFoundException: junit.framework.TestCase cannot be found by org.eclipse.xtext.junit_2.4.3.v201309030823
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 78 more

The exception happens when I run the tests for my Xtext DSL as plugin tests (i.e. when a new Eclipse platform is started internally). This happens before any of my code is executed.

When I look at the plugin dependencies, I can see that org.junit_4.11.0.v201303080030.jar is on the classpath and I also see /.../workspace/.metadata/.plugins/org.eclipse.pde.core/.external_libraries/org.junit_4.11.0.v201303080030/junit.jar

So OSGis should definitely be able to resolve this dependency.

Does Xtext 2.4.3 work with JUnit 4.11 or do I have to downgrade my Eclipse install to JUnit 4.10?

like image 239
Aaron Digulla Avatar asked Jan 16 '14 15:01

Aaron Digulla


People also ask

How to fix eclipse itself could not start in JUnit?

Check you Project's Run Configurations->JUnit->Classpath (tab ). JUnit should be under User Entries for your project. 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.

What is NoClassDefFoundError In JUnit?

1. Overview In this article, we'll understand why the java.lang.NoClassDefFoundError occurs in JUnit and how to fix it. This issue is mainly related to IDE's configurations. Therefore, we'll be focusing on the most popular IDEs: Visual Studio Code, Eclipse, and IntelliJ to reproduce and resolve this error.

What class is missing according to JUnit error?

What class is missing according the error? Right click your project in Package Explorer > click Properties click Next. select in dropdown button JUnit4 or other new versions. click finish. Then Ok. Just double-check that you have the Hamcrest library also on the classpath.

How to run test cases without the classnotfoundexception?

Open the problems view solve accordingly. Then ideally you will be able to run the test cases successfully without encountering the classnotfoundexception. Show activity on this post. Check eclipse.ini for some initialization variables that could possibly be fixed.


1 Answers

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.

like image 93
A Paul Avatar answered Oct 23 '22 10:10

A Paul