How can I add additional Android permissions for my UI test project only?

后端 未结 3 1046
再見小時候
再見小時候 2020-12-13 02:18

I try to write files to the external SD card in a from InstrumentationTestCase2 derived test case for pure testing purposes. This works all well when andr

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 03:07

    There is another easy answer.

    Set the permission in src/debug/AndroidManifest.xml. If the file doesn't exist, create it.

    By default, AndroidTest uses debug as BuildType, so if you define your testing permissions there, then the manifest merging process will add these permissions to your UI test build.

    Here is the Manifest with new permissions. Note that I didn't include the package attribute because it will be inherited from lower priority level manifest.

    
    
        
        
    
    

    Also, if you want to apply these permissions to a buildType other than debug, then just move your new AndroidManifest.xml to the folder you want, and use this:

    android {
       ...
       testBuildType 'release' // or other buildType you might have like 'testUI'
    }
    

提交回复
热议问题