I need android.permission.WRITE_SETTINGS for my Android application's junit tests. I am using IntelliJ Idea 11.1.2 and the unit tests in their own module, which contains second AndroidManifest.xml for the tests.
I added <uses-permission android:name="android.permission.WRITE_SETTINGS" />
to the test module's AndroidManifest.xml.
Error:java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=1063, uid=10035 requires android.permission.WRITE_SETTINGS
Ugly quick fix: I add the same permission also to the application's AndroidManifest.xml. Tests run without a single error.
The problem: I DO NOT want to give the whole application permission to change settings.
Is there a way to give permissions only for the tests?
Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow. Medium tests are in between and check the integration between two or more units.
Permission concept in Android. Android contains a permission system and predefined permissions for certain tasks. Every application can request required permissions. For example, an application may declare that it requires network access. It can also define new permissions.
To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .
Short answer is no.
Your Android Test Project and Android Application Project are actually two applications, with test.apk instruments app.apk and run time. <uses-permission> is per application, added it to the test project's AndroidManifest.xml only gives required permission to test.apk, not the application under testing i.e. app.apk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With