我正在使用 Kotlin 开发一个 Android 应用程序。我正在为我的应用程序编写仪器测试。我正在使用 GrantPermissionRule 在我的测试中授予权限,如下所示。
@get:Rule
var permissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION)
但是,这不符合我的要求。每次完成后,我都会清除所有授予的权限。另外,我喜欢测试未授予权限的场景。我像这样在我的测试中明确启动活动。
@Test
fun exampleTest() {
this.eventDetailsActivityRule.launchActivity(intent)
}
我喜欢在启动活动之后或之前使用 GrantPermissionRule 显式授予权限。我怎样才能做到这一点?