androidandroid-testingandroid-junit

Test Orchestrator Sample


Is anyone aware of a sample project that shows how to get test orchestrator working? I checked the google samples and there doesn't seem to be a good sample project that shows test orchestrator.

https://github.com/googlesamples/android-testing

I have been attempting to get android tests running in the test orchestrator but have been struggling to get it to work correctly. I tried both running the tests through Android Studio (latest 3.2.1) as well as the command line (https://developer.android.com/training/testing/junit-runner#ato-command-line). I used the Android developer document for reference.

https://developer.android.com/training/testing/junit-runner

Here are the steps I followed.

1) Create an empty activity application using the wizard in Android 
Studio 
2) Enable the test orchestrator using the steps provided here 
(https://developer.android.com/training/testing/junit-runner).
3) Run the unit tests from within the IDE and from the command line.

When I do this, I get an error indicating that my "test suite is empty". I get the same error running from command-line.

Note that if I run the test without test orchestrator, then the test runs successfully.

Also note that I am using the latest test orchestrator versions


Solution

  • The complete configuration to run test orchestrator:

    1. Add dependencies:
    dependencies {
        // <other dependencies>
        ...
    
        androidTestImplementation "androidx.test:runner:$testRunner"
        androidTestUtil "androidx.test:orchestrator:$testOrchestrator"
    }
    
    1. Add the clearpackagedata: true argument to defaultConfig in the app build.gradle, which removes all shared state from your device's CPU and memory after each test to run each test in isolation:
    defaultConfig {
        applicationId "com.example.android"
        ...
        
        // If debugging a test, disable this argument and the orchestrator
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }
    
    1. Add the Android/AndroidX orchestrator to testOptions:
    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
        ...
        
        // <other test options>
    }