I know this question has been asked in various forms before, but I've checked all the answers and I think we've 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
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 Runner Config:
Related Code functions fine when built into real project. So, any advice on what I might have missed?
I think your .iml is not updated. Have you tried re creating your project/module .iml files. If its maven project you can recreate it by command
mvn idea:idea
After .iml is updated refresh the project and re run the test
This got upvoted, so I'll let you know what we eventually worked out.
We were writing a plugin using the API for another application. When you deploy the plugin, it gains access to all the definitions in the application. However, the unit tests are running in isolation, so the particular classes that are only defined through interfaces and factories cannot be built.
For 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 never actually defined in our library path (the API jar was clearly built with it there, but it wasn't supplied).
There are multiple potential workarounds, hopefully smart people stumbling upon this question will comment with 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 issue are encapsulated away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With