IntelliJ NoClassDefFoundError when starting IntelliJ Tests

I know that this question was asked in different forms before, but I checked all the answers, and I think we excluded them all.

Error:

java.lang.NoClassDefFoundError: com/lgc/infra/geometry/Coord1Val at com.lgc.infra.geometry.Coords.coord(Coords.java:89) at com.lgc.infra.geometry.Coords.<clinit>(Coords.java:24) at com.geoteric.lfd.eos.ReallyBasicTest.make_a_simple_coord(ReallyBasicTest.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:24) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) Caused by: java.lang.ClassNotFoundException: com.lgc.infra.geometry.Coord1Val at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 37 more 

the code:

 package com.geoteric.lfd.eos; import com.lgc.infra.geometry.Coord3; import com.lgc.infra.geometry.Coords; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; /** * Created by TClarke on 27/03/2015. */ public class ReallyBasicTest { @Test public void make_a_simple_coord() { Coord3 c3 = Coords.coord(1.0f, 2.0f, 3.0f); assertThat(c3.getX(), equalTo(1.0)); } } 

Path to ClassFile:

 D:\ffa_dev\link-for-decisionspace\ext\dssdk\com_lgc_dsp-core_sdk.jar!\com\lgc\infra\geometry\Coords.class 

Screenshot of module structure:

Screenshot of test run configuration:

Functionality with consolidated code works great when building in a real project. So, any tips on what I might have missed?

+5
source share
2 answers

This was supported, so I will let you know what we eventually developed.

We wrote a plugin using the API for another application. When the plugin is deployed, it gains access to all application definitions. However, unit tests work in isolation, so specific classes that are defined only through interfaces and factories cannot be built.

In this example:

  Coord3 c3 = Coords.coord(1.0f, 2.0f, 3.0f); 

Both Coord3 and Coords are defined. But com / lgc / infra / geometry / Coord1Val, which is used in Coords, is not really defined in our path to the library (the API box was obviously built with it there, but it was not provided).

There are several possible workarounds that, we hope, smart people stumbling over this issue will comment on some of them. The one we went with is to wrap Coords in a mockable factory that returns mock (Coord3.class), so that the parts that demonstrate this problem are encapsulated.

+1
source

I think your .iml is not updating. You tried to re-create the project / module .iml files. If his project is maven you can recreate it with a team

 mvn idea:idea 

After updating .iml, update the project and run the test

0
source

Source: https://habr.com/ru/post/1216302/


All Articles