1

I'm getting the following crashing during an instrumentation test ONLY on emulators running API v19. If I run on newer versions everything works fine.

03-01 20:26:18.781 2878-2878/? E/MonitoringInstrumentation: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords. java.lang.NoClassDefFoundError: org.objenesis.ObjenesisStd at org.mockito.internal.creation.jmock.ClassImposterizer.(ClassImposterizer.java:36) at org.mockito.internal.creation.jmock.ClassImposterizer.(ClassImposterizer.java:29) at org.mockito.internal.util.MockCreationValidator.isTypeMockable(MockCreationValidator.java:17) at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:21) at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:133) at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:127) at org.mockito.internal.MockitoCore.mock(MockitoCore.java:50) at org.mockito.Mockito.mock(Mockito.java:1243) at org.mockito.Mockito.mock(Mockito.java:1120)

The problem is this line:

java.lang.NoClassDefFoundError: org.objenesis.ObjenesisStd

My app is multi-dex, and I'm using dexmaker-mockito for androidTestCompile. I'm at a complete loss why this only breaks on an older API. It started happening when I added another module to my project, which is a pure java module with no dependency on mockito.

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187

1 Answers1

0

This exception (ClassNotFoundException) tells you about a unmet dependency at runtime: the JVM needs to load a class; which is not present in the class path.

Here it is Mockito that needs Objenesis. Normally that library should be pulled automatically when you a system like maven and give the correct dependency to Mockito.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • Objenesis is list in the dependency tree for androidTestCompile when I output the dependencies via Gradle. What's really odd is that this only happens on Android API v19 devices and below. – Christopher Perry Mar 02 '17 at 17:59