Android Marshmallow: Test permissions with Espresso?

前端 未结 13 1386
庸人自扰
庸人自扰 2020-11-29 19:31

The new permissions scheme introduced by Android Marshmallow requires checking for specific permissions at runtime, which implies the need to provide different flows dependi

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 20:15

    ESPRESSO UPDATE

    This single line of code grants every permission listed as parameter in the grant method with immediate effect. In other words, the app will be treated like if the permissions were already granted - no more dialogs

    @Rule @JvmField
    val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION)
    

    and gradle

    dependencies {
      ...
      testImplementation "junit:junit:4.12"
      androidTestImplementation "com.android.support.test:runner:1.0.0"
      androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.0"
      ...
    }
    

    reference: https://www.kotlindevelopment.com/runtime-permissions-espresso-done-right/

提交回复
热议问题