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
java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider
This is my test case
@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<Sms> tenSms = new SmsFetcher(appContext)
.limit(10)
.get();
assertEquals(10, tenSms.size());
}
}
I'm new to instrumented tests. Is this is proper way to do this?
Or am I missing something?