How to manage Runtime permissions android marshmallow espresso tests

后端 未结 12 924
孤独总比滥情好
孤独总比滥情好 2020-12-05 02:33

I\'m using espresso for testing but sometimes I try to get an image form external storage and with marshmallow I need a Runtime permission otherwise there will be an Excepti

12条回答
  •  春和景丽
    2020-12-05 03:22

    You can grant and revoke permissions using:

    adb shell pm grant com.package.myapp android.permission.
    adb shell pm revoke com.package.myapp android.permission.
    

    To use from Java instrumentation tests call this method from Google samples: https://github.com/googlesamples/android-testing/blob/ed62c450e43f859333b3113d44dd59f75971b529/ui/espresso/IntentsBasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/DialerActivityTest.java#L94

提交回复
热议问题