title: Unit testing on Android Studio: "not mocked" error
body: <p>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. </p>
  
  <p>I cannot get around this error, when trying to run my unit tests:</p>
  
  <pre><code>java.lang.RuntimeException: Method getInstrumentation in android.test.InstrumentationTestCase not mocked
  </code></pre>
  
  <p>This is my test class:</p>
  
  <pre><code>public class AppPreferencesTest extends InstrumentationTestCase {
  
  AppPreferences preferences;
  
  @Before
  public void setUp() throws Exception {
      preferences = new AppPreferences(getInstrumentation().getTargetContext());
  }
  
  ...
  </code></pre>
  
  <p>In my build.gradle:</p>
  
  <pre><code>testCompile 'junit:junit:4.12'
  </code></pre>
  
  <p>I tried adding this</p>
  
  <pre><code>testOptions { 
      unitTests.returnDefaultValues = true
  }
  </code></pre>
  
  <p>because that was mentioned in the steps that I followed at <a href="http://tools.android.com/tech-docs/unit-testing-support" rel="noreferrer">http://tools.android.com/tech-docs/unit-testing-support</a>
  but it does not fix it.</p>
  
  <p>I also tried creating a MockContext:</p>
  
  <pre><code>preferences = new AppPreferences(new MockContext());
  </code></pre>
  
  <p>but the constructor of AppPreferences than gives an error</p>
  
  <pre><code>public AppPreferences(Context context) {
      preferences = PreferenceManager.getDefaultSharedPreferences(
              context);
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>RuntimeException: Method getDefaultSharedPreferences in android.preference.PreferenceManager not mocked.
  </code></pre>