I\'m using Espresso and UIAutomator to write my test cases. I\'m testing external storage permissions when it\'s denied and when it\'s allowed. I have different test cases w
You should not revoke any permission before the tests start. This will restart the entire test app process and the test will be marked as failure.
Instead you can revoke the permission after test execution is completed i.e. in @After method as follows:
@After
fun tearDown(){
InstrumentationRegistry.getInstrumentation().uiAutomation.
executeShellCommand("pm revoke ${getTargetContext().packageName} android.permission.WRITE_EXTERNAL_STORAGE")
}
Alternatively, you can use Android Test Orchestrator version 1.0.2 and set
testInstrumentationRunnerArguments clearPackageData: 'true'
this will clear the package data after each test.
Note: Android Test Orchestrator v1.0.2 has issues when it comes to managing code coverage reports via Jacoco.