11

Is there any way to run tests against Release build type or any other custom build variant?

The default behaviour of connectedInstrumentTest task is to run tests only against the Debug build variant

Any ideas?

gemini
  • 349
  • 4
  • 11

1 Answers1

20

AFAIK connectedInstrumentTest runs against the build type specified with the testBuildType attribute. You could try to make this dynamic reading it from the command line arguments:

android {
    testBuildType obtainTestBuildType()
}

def obtainTestBuildType() {
    def result = "debug";

    if (project.hasProperty("testBuildType")) {
        result = project.getProperties().get("testBuildType")
    }

    result
}

And then call it with

./gradlew connectedInstrumentTest -PtestBuildType=release

rciovati
  • 27,603
  • 6
  • 82
  • 101
  • Thanks for that. This looks reasonable but the commandline variable looks like it is omitted. fyi:I am using buildToolsVersion "19.0.1" gradlew dist (gradle-1.10) – gemini Feb 13 '14 at 16:07
  • You are right. Looks like I used a wrong method name, try changing it (see updated answer). – rciovati Feb 13 '14 at 16:26
  • 1
    Great just realised that. Another issue occurred now is that ... when I try to run ./gradlew connectedInstrumentTest -PtestBuildType=release Unable to find instrumentation info for: ComponentInfo{com.example.app.tests/com.example.app.tests.SpoonInstrumentationTestRunner} SpoonInstrumentationTestRunner.java lives inside the default instrumentTest directory which not relate to a specific build type Any ideas will be much appreciated? – gemini Feb 13 '14 at 16:36
  • 1
    When I tried this with Proguard enabled on my release buildType, the build failed because the `:proguardReleaseTest` task failed due to [**a lot** of warnings](https://gist.github.com/JaKXz/10159871) about classes not being able to find referenced classes. @rciovati any ideas? – JaKXz Apr 08 '14 at 17:30
  • Shouldn't you be returning the result from the method? – Daniel Ochoa Dec 22 '14 at 17:09
  • 1
    ./gradlew connectedAndroidTest -PtestBuildType=release for 2018 – bj4947 Jan 19 '18 at 06:59