0

I've found the code to actually test the permissions. But I don't know how to delete the permissions given (or denied) in order to test every case.

Any idea? Every solution found doesn't work by now (runtime exec, get activity and clear data, etc.)

Any idea would be appreciated.

Filnik
  • 352
  • 1
  • 12
  • 33
  • 1
    Have you tried this solution? https://stackoverflow.com/questions/43462172/android-revoke-permission-at-start-of-each-test – janavarro Mar 10 '20 at 12:30
  • it almost works. I mean, the first test runs correctly and erases the permissions but the second crashes. Maybe something stay opened, I don't know – Filnik Mar 10 '20 at 17:34
  • 1
    check out this link : https://github.com/ahasbini/AndroidTestMockPermissionUtils – Jaspalsinh Gohil Mar 11 '20 at 05:31
  • I think that the premises of that readme are wrong. I mean, I am able to reset the permissions at runtime before the first test start. He states that he wasn't able to do that. My problem is that at the second run I got a "DeadObject" when I invoke the call to reset the permissions and I cannot understand why – Filnik Mar 11 '20 at 10:29
  • So you claim that `clearPackageData true` doesn't work for you? – azizbekian Mar 12 '20 at 19:33
  • @Filnik, the "DeadObject", where is this error coming from or showing in? How are you executing or running your tests? Are you using Roboelectric? – ahasbini Mar 13 '20 at 17:17

1 Answers1

0

You can use the test orchestrator.

First, you add this to the gradle of the module with the tests that you want the permissions to be cleared for.

androidTestUtil 'androidx.test:orchestrator:version'

and in the same gradle, you add this to the defaultConfig block in the android block.

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'

The docs are here if you want more info: https://developer.android.com/training/testing/instrumented-tests/androidx-test-libraries/runner

John Glen
  • 771
  • 7
  • 24