jenkinsci / peass-ci-plugin

Jenkins plugin for peass to support performance measurement in CI
https://plugins.jenkins.io/peass-ci/
GNU Affero General Public License v3.0
4 stars 12 forks source link

Add permission rules for emulated tests #168

Closed alex-iotiq closed 1 year ago

alex-iotiq commented 2 years ago

To be able to write/read files inside the emulator (for temporary results), you have to add permissions. Usually those permissions have to be granted at runtime, but with tests you can add a special rule to grant them automatically.

First you need to add permissions

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

to app/src/main/AndroidManifest.xml:

<manifest ... package="com.example.android_example">
    ...
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    ...
    <application
        ...
        android:requestLegacyExternalStorage="true"
        ...
    >

And then adding permission rules to the tests which are run like this:

import android.Manifest;
import androidx.test.rule.GrantPermissionRule;
import org.junit.Rule;

@RunWith(AndroidJUnit4.class)
public class InstrumentedTest {
...
    @ClassRule
    public static GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    ...

Add dependency to app/build.gradle (related #171):

...
dependencies {
    ...
    androidTestImplementation 'androidx.test:rules:1.4.0'
    ...
}

This means there are 3 requirements:

DaGeRe commented 2 years ago

The last one should work starting with https://github.com/DaGeRe/peass/commit/b803de7dc18e8b80c06c259cd39138ea8b02378b

DaGeRe commented 2 years ago

Adding the rule now also works: https://github.com/DaGeRe/peass/commit/f68feef3a69ee5fcf5dcba6ad91cc9ddb6a16409