Run unittests just on one build variant with gradle

2k Views Asked by At

I have a multi dimensional android gradle Project which takes long to build and long to test. I have a two dimensional flaver definition. the first dimensions has 2 project values , the second dimension has 4 environment definitions , and there are 3 build types.

this results in 2x4x3 = 24 build variants. I would like to optimize in a way, that just one build variant would be builded and only one build variant would be used for running the unittests in the ci-environment.

build.gradle

android {
// more configurations
flavorDimensions "project", "environment"

productFlavors {
basic  {
    dimension "project"
}

advanced {
    dimension "project"
}

flavorDevelopment {
    dimension "environment"
    applicationId "ch.myproject.app.development"
}

flavorTest {
    dimension "environment"
    applicationId "ch.myproject.app.test"
}

flavorIntegration {
    dimension "environment"
    applicationId "ch.myproject.app.integration"
}

flavorProduction {
    dimension "environment"
    applicationId "ch.myproject.app.production"
}

buildTypes {
    debug {
        testCoverageEnabled = true
        minifyEnabled = false
        shrinkResources = false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }

    debugInstantRun.initWith(buildTypes.debug)
    debugInstantRun {
        // we are changing this build variant later on runtime, so that it will use constant values
        // for versionCode and versionName in the Manifest, for make sure the
        // manifest is unchanged between the instantRun builds

        // Specifies a sorted list of fallback build types that the
        // plugin should try to use when a dependency does not include a
        // "debugInstantRun" build type. You may specify as many fallbacks as you
        // like, and the plugin selects the first build type that's
        // available in the dependency.
        matchingFallbacks = ['debug']
    }

    release {
        // Currently all environments (dev/test/int/prod) are signed by the Production certificates
        minifyEnabled = false
        shrinkResources = false
    }
}
// more configurations
} // end of android

I would previous clean everything, gradlew clean --refresh-dependencies

then just assembling the Debug variants, gradlew assembleDebug

and then I try running just the unittest on one debug variant: gradlew testAdvancedFlavorDevelopmentDebugUnitTest -> This does not work

if I run gradlew test all the build variants are builded (exept Release build types) ,the tests are working but this takes ways to long!

also tried to gradlew testDebugUnitTest -> does not work

I think I could move the unittests into another directory than test e.g testAdvancedFlavorDevelopment then when i would enter gradlew test just the tests for testAdvancedFlavorDevelopmentDebug and testAdvancedFlavorDevelopmentDebugInstantRun would be started.

But there must be a way to let the tests be in the test directory and enforce by gradlew command to just to compile and unittest just one specific buildvariant! Any ideas?

tia luke

1

There are 1 best solutions below

0
On

try ./gradlew :ModuleName:testVariantNameUnitTest, also you can find in the Gradle tab all the possible UnitTest tasks that you can execute.

enter image description here