3

I am currently testing my sample app using Android instrumentation test. By default, the project creates AndroidTest folder for me. I simply just added more test cases into the folder.

I used to use expresso to trigger the UI buttons, but now I want to test use androidTest only, However, the androidTest does not seem to test my release build. I have two variants productionRelease and stageDebug in this case.

Every time I started the project by

./gradlew mysample:connectedCheck 

or

./gradlew mysample:connectedAndroidTest

it tests only

Task :mysample:connectedStageDebugAndroidTest

If I want to manually start a task

./gradlew mysample:connectedProductionReleaeAndroidCheck 

It complains tasks not found in mysample

* What went wrong:
Task 'connectedProductionReleaseAndroidTest' not found in project ':mysample'.

Isn't connectCheck supposed to test all the variants in my project? (StageDebug and ProductionRelease)

from task --all

mysample:connectedCheck - Runs all device checks on currently connected devices.
mysample:connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
bj4947
  • 880
  • 11
  • 32
  • 1
    Possible duplicate of [Android Gradle Running Tests on Non-Debug Builds](https://stackoverflow.com/questions/23923218/android-gradle-running-tests-on-non-debug-builds) – Martin Zeitler Jan 18 '18 at 00:58

1 Answers1

4

Just tried... one can simply run ./gradlew mysample:testDebugUnitTest and ./gradlew mysample:testReleaseUnitTest - which runs the tests for either debug or release build. one can add the annotation @RequiresDevice to tests, in case eg. one requires hardware sensors.

productionRelease and stageDebug seem over-complicated (and it also not matches the rest of the naming - unless there would be productionDebug and stageRelease as well), resulting in even longer task names, would suggest to shorten...

buildTypes {
    debug {}
    release {}
}

Here when I run ./gradlew mysample:connectedAndroidTest I rather get a

Execution failed for task ':mysample:connectedDebugAndroidTest'. com.android.builder.testing.api.DeviceException: No connected devices!

After closing Android Studio (and the ADB daemon it started), I can run the tests on hardware device. there only is a installDebugAndroidTest task, but no installReleaseAndroidTest task. testBuildType 'release' might run the tests against the release build - the problem is just that androidTestImplementation most likely is not contained then (quite useless).

Martin Zeitler
  • 1
  • 19
  • 155
  • 216