I consider that Android Studio will run test before generate signed apk.
But AS didn't do that for me.It's not nice before package my apk, I need run the tests myself.
I'm not sure if dependsOn or other way can help me.I'm not sure weather my build.gradle has mistakes.
Some relevant code in gradle maybe like this:
defaultConfig {
applicationId "com.xx.xx"
versionCode getDefaultVersionCode()
minSdkVersion 19
targetSdkVersion 19
}
dependencies {
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'junit:junit:4.12'
}
I didn't write testOption.
My directory is like this(content before them is package name):
To run all available tests, when building a release, make the task, that builds the release (e.g. assembleRelease
) depend on the test tasks:
android {
// ...
}
afterEvaluate {
assembleRelease.dependsOn testReleaseUnitTest, connectedAndroidTest
}
The afterEvaluate
closure is executed after evaluation (when the android tasks have been created). At this time the android tasks can be referenced as variable.
Instead of testReleaseUnitTest
you can just use test
, which runs unit tests for all variants.
Keep in mind that there are by default no instrumentation tests for the release
version of your app (build with assembleRelease
). So in the above example, connectedAndroidTest
runs the instrumentation tests for the debug
version only.
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