Android Marshmallow: Test permissions with Espresso?

前端 未结 13 1391
庸人自扰
庸人自扰 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:25

    I know an answer has been accepted, however, instead of the if statement that has been suggested over and over again, another more elegant approach would be to do the following in the actual test you want for a specific version of OS:

    @Test
    fun yourTestFunction() {
        Assume.assumeTrue(Build.VERSION.SDK_INT >= 23)
        // the remaining assertions...
    }
    

    If the assumeTrue function is called with an expression evaluating to false, the test will halt and be ignored, which I am assuming is what you want in case the test is being executed on a device pre SDK 23.

提交回复
热议问题