Issue
I'm trying to setup a test project like is described in the Android Testing Blueprint but I receive the following NoClassDefFoundError:
java.lang.NoClassDefFoundError: android.test.mock.MockContentResolver
Android Studio resolves this correctly but when running I receive this error.
It's worth to note that I do not have an androidTest configuration on the app project, instead I only have a separate tests module with:
apply plugin: 'com.android.test'
I'm running tests like this:
./gradlew :tests:connectedAndroidTest
Test project to reproduce this issue can be found here: https://github.com/vexdev/android-testing-templates/tree/master/AndroidTestingBlueprint
EDIT: Also asked on Android Development community
EDIT: Also created following android issue: https://code.google.com/p/android/issues/detail?id=200182&thanks=200182&ts=1454489567
Solution
Some android packages are not automatically linked, but you have to explicitly specify them using the <uses-library> tag. That is the case with the android.test package (see uses-library docs), like @rds mentioned.
Adding a compile dependency will work if you have minSdkVersion > =15, but will add a legacy Maven artifact that has been updated on the Aug 24, 2012 for the last time.
IMHO, it might be a better solution to add the following snippet to the manifest of the test module:
<application>
<uses-library android:name="android.test.runner" />
</application>
This will tell the system to include the android.test package as well, so the MockContentResolver will be found by the class loader.
Hope it helps.
Answered By - Ivan Gavrilovic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.