To run all available tests when creating a release, the task that creates the release (for example, assembleRelease ) depends on the test tasks:
android {
Closing afterEvaluate is done after evaluation (when android tasks were created). At this time, android tasks can be specified as variables.
Instead of testReleaseUnitTest you can simply use test , which runs unit tests for all options.
Keep in mind that by default there are no benchmarks for the release version of your application (build with assembleRelease ). Thus, in the above example, connectedAndroidTest runs control tests for the debug version only.
source share