Android Marshmallow:使用Espresso测试权限? [英] Android Marshmallow: Test permissions with Espresso?

查看:122
本文介绍了Android Marshmallow:使用Espresso测试权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Marshmallow引入的新权限方案要求在运行时检查特定权限,这意味着需要根据用户是拒绝还是允许访问来提供不同的流程.

The new permissions scheme introduced by Android Marshmallow requires checking for specific permissions at runtime, which implies the need to provide different flows depending on whether the user denies or allows access.

当我们使用Espresso在我们的应用上运行自动化的UI测试时,如何模拟或更新权限状态以测试不同的情况?

As we use Espresso to run automated UI tests on our app, how can we mock or update the state of the permissions in order to test different scenarios?

推荐答案

With the new release of the Android Testing Support Library 1.0, there's a GrantPermissionRule that you can use in your tests to grant a permission before starting any tests.

@Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);

科特林溶液

@get:Rule var permissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION)

必须使用

@get:Rule以避免java.lang.Exception: The @Rule 'permissionRule' must be public.更多信息此处.

@get:Rule must be used in order to avoid java.lang.Exception: The @Rule 'permissionRule' must be public. More info here.

这篇关于Android Marshmallow:使用Espresso测试权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆