I have some android instrumented tests under AndroidTests directory in Android Studio. Of course I can manually execute the tests but I need to execute all the tests in the suite after each build ("release" type of build, not during normal debug build). I need to do that because I'd like to validate the new code against the tests before releasing the new app's apk. How to do that? I google it but I didn't find a proper solution yet.
Any idea?
Finally I managed to do that. I have added the following configuration to my build.gradle file in my android studio project:
// execute android tests before realising a new apk
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease')
task.dependsOn('connectedAndroidTest')
}
android {
signingConfigs {
release {
keyAlias 'key'
keyPassword 'password'
storeFile file('/path/to/release_keystore.jks')
storePassword 'password'
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
After doing that I'm able to run all android tests when building a release apk. If the tests are failing no apk is built.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With