I am new to Android Studio. I am using Android Studio 1.2 preview 2, gradle 2.2.1 and gradle plugin 1.1.0.
I cannot get around this error, when trying to run my unit tests:
java.lang.RuntimeException: Method getInstrumentation in android.test.InstrumentationTestCase not mocked
This is my test class:
public class AppPreferencesTest extends InstrumentationTestCase {
AppPreferences preferences;
@Before
public void setUp() throws Exception {
preferences = new AppPreferences(getInstrumentation().getTargetContext());
}
...
In my build.gradle:
testCompile 'junit:junit:4.12'
I tried adding this
testOptions {
unitTests.returnDefaultValues = true
}
because that was mentioned in the steps that I followed at http://tools.android.com/tech-docs/unit-testing-support but it does not fix it.
I also tried creating a MockContext:
preferences = new AppPreferences(new MockContext());
but the constructor of AppPreferences than gives an error
public AppPreferences(Context context) {
preferences = PreferenceManager.getDefaultSharedPreferences(
context);
}
...
RuntimeException: Method getDefaultSharedPreferences in android.preference.PreferenceManager not mocked.