How to grant permissions to android instrumented tests? : <p>I have an application that reads SMSs. The app works fine when debugging but when testing it using android instrumented test it throws the following error</p>

<pre><code>java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider
</code></pre>

<p>This is my test case</p>

<pre><code>@RunWith(AndroidJUnit4.class)
public class SmsFetcherTest {

   @Test
   public void fetchTenSms() throws Exception {
      // Context of the app under test.
      Context appContext = InstrumentationRegistry.getContext();

      //   Fails anyway.
      //   assertTrue(ContextCompat.checkSelfPermission(appContext,
      //     "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED);

      List&lt;Sms&gt; tenSms = new SmsFetcher(appContext)
              .limit(10)
              .get();

      assertEquals(10, tenSms.size());
   }
}
</code></pre>

<p>I'm new to instrumented tests. Is this is proper way to do this?</p>

<p>Or am I missing something?</p>
