我有一个可以读取短信的应用程序。当我在调试时,这个应用程序运行良好,但是当我使用安卓仪器化测试进行测试时,它会抛出以下错误:
java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider
这是我的测试用例
@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());
}
}
我对仪器测试不太熟悉,这样做是否正确?
或者我有什么遗漏吗?