JUnit NoClassDefFoundError on org.junit.Assert

When this code is run, the following error occurs: (ColorMatrix getarray()returns float [])

74 public void testHueShift() {
75     ColorMatrix cm1 = new ColorMatrix();
76     ColorMatrix cm2 = hueShift(0f);
77     assertArrayEquals(cm1.getArray(), cm2.getArray(), 0f);
78 }

error:

 ----- begin exception -----
 java.lang.NoClassDefFoundError: org.junit.Assert
    at com.Common.lib.test.ColorFilterFactoryTest.testHueShift(ColorFilterFactoryTest.java:77)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
 ----- end exception -----

But the way to build a project has it:

enter image description here

EDIT
This is the class class path Test enter image description here

This is a test class (this is a library project) enter image description here

+4
source share
1 answer

The stack trace contains a hint for a solution: it contains junit.framework.TestCase(therefore, this class is on the class path), but it cannot be found later org.junit.Assert.

It looks like you are using JUnit 3.8 in the classpath when running the test, but JUnit 4 when compiling.

, unit test .

+3

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


All Articles