Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MockContentResolver is not found in an Android Test project with separate module

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

like image 928
Luca Vitucci Avatar asked Mar 13 '23 10:03

Luca Vitucci


1 Answers

As @rds said, test package is not part of the framework on the device, therefore you need to include the package.

Seems like com.android.test plugin is not adding those classes, so you can fix it by adding

compile 'com.google.android:android-test:4.1.1.4'

in your dependencies for the module where you are applying the plugin.

like image 60
Ljubisa Avatar answered Apr 14 '23 14:04

Ljubisa