handstandsam / AndroidHttpMockingExamples

"androidTest" Examples for WireMock 2.x and okhttp MockWebServer 3.x
Apache License 2.0
40 stars 11 forks source link

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

Open alexei28 opened 7 years ago

alexei28 commented 7 years ago

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.

alexei-28 commented 7 years ago

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.

handstandsam commented 6 years ago

@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.