AndroidHttpMockingExamples icon indicating copy to clipboard operation
AndroidHttpMockingExamples copied to clipboard

Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

Open alexei28 opened this issue 8 years ago • 2 comments

I download this project (AndroidHttpMockingExamples). Import to Android Studio 2.3.

When start WireMockAndroidTest1.testWiremock() on Android 7.0 it work.

But when start WireMockAndroidTest1.testWiremock() on Android 4.3 I get error:

$ adb shell am instrument -w -r -e debug false -e class com.handstandsam.httpmocking.tests.wiremock.WireMockAndroidTest1#testWiremock weatherview.joshskeen.com.weatherview.test/android.support.test.runner.AndroidJUnitRunner Client not ready yet.. Started running tests Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError' Empty test suite.

alexei28 avatar Apr 27 '17 17:04 alexei28

I found solutions of problem:

If you use Android 5.0- (e.g. Android 4.3) then you MUST use Wiremock version 2.0.8-beta androidTestCompile 'com.github.tomakehurst:wiremock:2.0.8-beta'

If you use Android 5.0+ you can you use any Wiremock version (e.g. 2.5.0) androidTestCompile 'com.github.tomakehurst:wiremock:2.6.0'

P.S. Maybe this is a Multidex issues.

alexei-28 avatar May 20 '17 08:05 alexei-28

@alexei28 & @lmdic - This is an issue with Mutlidex not being supported on Test APKs. If you want to run on APIs less than Lollipop (API 21) - Android 5.0, then you'd need to run proguard on your test APK and strip out a lot of unused classes.

Unfortunately I don't have a good example of this at the moment, and the proguard rules would vary depending on the features of wiremock you are using.

If it's important to test on less than API 21, I would suggest trying other libraries like MockWebServer.

handstandsam avatar Sep 18 '17 03:09 handstandsam