NoClassDefFoundError on CI but works locally

Hi,
I have a problem with unit tests working locally but failing on CircleCi with errors like:

java.lang.NoClassDefFoundError: Could not initialize class org.mockito.Answers
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

and

java.lang.NoSuchMethodError: ‘org.mockito.internal.runners.InternalRunner org.mockito.internal.runners.RunnerFactory.createStrict(java.lang.Class)’
at org.mockito.junit.MockitoJUnitRunner.(MockitoJUnitRunner.java:154)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

and

java.lang.ExceptionInInitializerError
at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.(ConditionalStackTraceFilter.java:17)
at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:41)
at org.mockito.exceptions.base.MockitoException.(MockitoException.java:30)

Has anyone run into similar problem and could help?

Hello

Would it be possible to add the following to your tests.

import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ExampleTest {
    //...
}

If the issue is still ongoing or if you need more assistance please feel free to raise a support ticket from our support portal linked here: https://support.circleci.com/hc/en-us/requests/new

You can find more information and more options at the link below

Kind Regards

Owen