Search code examples
androidandroid-testingandroid-signing

How to run unit tests for Generate Signed Bundle / APK action


How to automatically run unit tests before signing a bundle using "Build -> Generate Signed Bundle" action in Android Studio?


Solution

  • Add below configuration to your module's build.gradle file:

    For unit tests:

    afterEvaluate {
        bundleRelease.dependsOn testReleaseUnitTest
    }
    

    For both unit tests and instrumentation tests use:

    afterEvaluate {
        bundleRelease.dependsOn testReleaseUnitTest, connectedAndroidTest
    }