6

I have around 25 tests on my android tests package. I have some tests that I to run during integration and some tests that run as normal instrumentation tests. I am trying to call the integration tests using Gradle tasks but it seems impossible for instrumentation tests. I have checked for unit tests and it's possible with something like this-

task integrationTest(
        type: Test,
        description: 'Run integration tests only. Pass in \'-Pintegration=true\'',
        dependsOn: ['testDebugUnitTest', 'clean'] ) {

    //Here for task completion, not actually used since sub task of testDebugUnitTest
    testClassesDir = file("src/integrationTest/java/");
    classpath = files("$System.env.ANDROID_HOME/sources/android-18")

    //
    //Turn on integration testing when argument exists and is true
    //
    if (project.hasProperty('integration')) {
        println integration
        if (integration == 'true') {
            integrationTests = true
        }
    }
}

and doing something like this

testOptions {
        unitTests.all {
            useJUnit()
            if (integrationTests.toBoolean()) {
                println "Integration Tests Only for " + it.name
                options {
                    excludeCategories 'com.example.reactivemvp.categories.UnitTest'
                }
            } else {
                println "Unit Tests Only for " + it.name
                options {
                    excludeCategories 'com.example.reactivemvp.categories.IntegrationTest'
                }
            }
        }
    }

I have seen that the testOptions only works with unit tests and not with instrumentation tests. I found out what is the method for access the instrumentation tests-

testVariants.all { variant ->
        if(connectedInstrumentTest.name)
        variant.connectedInstrumentTest.doFirst {
            println "This will be executed right after our connectedInstrumentTest!"
            println "The name of the test type: $connectedInstrumentTest.name"
            if (intergrationTests == true) {
                exclude '**/*androidTest.functionalTests*'
            }

        }
    }

I get the error as

Could not find method exclude() for arguments [**/*androidTest.functionalTests*] on task ':app:connectedAndroidTest'

Is there a way to call only a section of the instrumentation tests by some Gradle task?

Dinesh
  • 889
  • 14
  • 34

0 Answers0