Tuesday, 30 October 2018

Android UI Tests with Storage Permissions in CI

I want to run UI tests and unit tests on a project in CI (Jenkins Pipeline). The UI tests requires images and video to be on the test device / emulator. In the UI tests I request permission for storage read/write access so I can dump a few assets into the downloads folder, then at the end of the test suite I remove them.

When I run my tests on Jenkins (mac) permissions are not granted, no media transfers over, and all of my tests fail.

The project contains an app module and two in-house library modules.

Pipeline steps

Build

sh "./gradlew clean assembleRelease"

Unit Test

sh "./gradlew testReleaseUnitTest"

UI Test

sh "$ANDROID_HOME/emulator/emulator @my_sweet_emulator_name -no-boot-anim & $ANDROID_HOME/platform-tools/adb wait-for-device"
sh './gradlew connectedAndroidTest'

Issues

1) The CI build hangs on the implicit assembleDebugAndroidTest task

2) If I run that task on the command line on my computer the tests will install however the permission is not granted to read/write storage so all tests fail.

Things I've Tried

  • I have attempted only testing a release build however this shows the same issue 2. testBuildType "release"
  • I have no other permissions I need to work with

How I'm granting permissions

@RunWith(AndroidJUnit4::class)
class MyMediaClassTest {

    @Rule
    @JvmField
    val activityRule = ActivityTestRule(MainActivity::class.java)

    @Rule
    @JvmField
    val grantPermissionRule: GrantPermissionRule = GrantPermissionRule
            .grant(android.Manifest.permission.READ_EXTERNAL_STORAGE,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
// tests and stuff
}

I have seen a potential solution to manually copy all of my media assets into the emulator image. But that doesn't seem right, this should be able to be automated.



from Android UI Tests with Storage Permissions in CI

No comments:

Post a Comment