bigdestroyer bigdestroyer - 2 months ago 13
Android Question

Setting up integration tests in Android Gradle-based project

I'm following this tutorial to add integration test env to my Android project.
I have create

src/integrationTest/java
and
src/integrationTest/resources
dirs and then I have added this to my
build.gradle
:

sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integrationTest/java')
}
resources.srcDir file('src/integrationTest/resources')
}
}


But when I sync Gradle files I get this error:


Error:(134, 0) No such property: main for class:
org.gradle.api.internal.file.DefaultSourceDirectorySet Possible
solutions: name


What does it means? How can I solve it?

Thanks

EDIT

I have just tried with
android.sourceSets.main.output
and
android.sourceSets.test.output
instead of
main.output
and
test.output
, respectively:

sourceSets {
integrationTest {
java {
compileClasspath += android.sourceSets.main.output + android.sourceSets.test.output
runtimeClasspath += android.sourceSets.main.output + android.sourceSets.test.output
srcDir file('src/integrationTest/java')
}
resources.srcDir file('src/integrationTest/resources')
}
}


And now I get this error:


Error:(136, 0) Could not find property 'output' on source set main.

Answer

Solved! Actually, these lines don't have to be in source set config, but in the task that runs integration tests. Now, my build.gradle looks like:

    sourceSets {
        integrationTest {
            java.srcDir file('src/integrationTest/java')
            resources.srcDir file('src/integrationTest/resources')
        }
    }

    configurations {
        integrationTestCompile.extendsFrom testCompile
    }

    task integrationTest(type: Test) {
        testClassesDir = sourceSets.integrationTest.output.classesDir
        classpath = sourceSets.integrationTest.runtimeClasspath
    }