androidunit-testingandroid-studioandroid-instrumentation

Run all unit tests in Android Studio


I have this project in Android Studio :

enter image description here

I wish to run all unit tests in all project with one click.

How i can do it ?


Solution

  • First, you can list all the test tasks available in your project with

    ./gradlew tasks
    

    Then you can choose the tasks you want to execute. If you want to execute all tests for all flavors ans all buildTypes, you just have to run

    ./gradlew test connectedAndroidTest
    

    If you don't want to remember all the gradle test command each time you want to run the tests, you can create a file "custom_tasks.gradle" and add

    task testAll(dependsOn: ['test', 'connectedAndroidTest']) {
       group = 'custom_tasks'
       description = "Run all tests"
    }
    

    Then, you just have to run

    ./gradlew testAll