How to manage Runtime permissions android marshmallow espresso tests

后端 未结 12 919
孤独总比滥情好
孤独总比滥情好 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:32

    You can use GrantPermissionRule. This rule will grant all the requested runtime permissions for all test methods in that test class.

    @Rule 
    public GrantPermissionRule mRuntimePermissionRule
                = GrantPermissionRule.grant(Manifest.permission.READ_PHONE_STATE);
    

提交回复
热议问题