Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up integration tests in Android Gradle-based project

Tags:

android

gradle

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.

like image 749
Héctor Avatar asked Nov 17 '15 07:11

Héctor


People also ask

What is integrationtest in Gradle?

When we added a test set called integrationTest into our build, the Gradle TestSets plugin created a task called integrationTest that runs our integration tests. However, because we need to fulfill the requirements of our Gradle build, we have to make some changes to its configuration. We can make these changes by following these steps:

How to add a new test set in Gradle?

Let’s start by adding a new test set into our Gradle build. We can add new test sets into our Gradle build by using the Gradle TestSets plugin. Before we will apply this plugin, we have to know that we can use this plugin only if we are also using the java and/or groovy plugin. We can apply the Gradle TestSets plugin by following these steps:

What is the use of Gradle in spring testing?

It allows you to specify additional test sets and add these test sets to your build. If you want learn how to use Gradle for running unit, integration, and end-to-end tests, which ensure that your Spring web application is working as expected, take a look at my upcoming Test With Spring Course.

What are the requirements of a Gradle build?

The requirements of our Gradle build are: Our integration tests must have a separate source directory. The src/integration-test/java directory must contain the source code of our integration tests. Our integration tests must have a separate resource directory.


1 Answers

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
    }
like image 111
Héctor Avatar answered Oct 23 '22 11:10

Héctor