Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Gradle for multiple Android instrumentation test folders

I have two different types of instrumentation tests for my Android app, each of which require different instrumentation test runner classes.

I have been unable to find a clean way of encapsulating these test runners into a single class, and am now looking to separate these tests into two suites each with its own instrumentation test runner.

Is it possible to create another test folder alongside androidTest, and how can this be configured within my build.gradle?

like image 211
funkybro Avatar asked Sep 21 '16 18:09

funkybro


1 Answers

Create a new folder on the same level as test and androidTest (e.g.: I created one called acceptanceTest).

Then, in your module's build.gradle file include this outside the android { } block:

android.sourceSets {
    androidTest {
        java.srcDirs += "$projectDir/src/acceptanceTest"
    }
}

Now you will be able to run instrumented tests on this new folder too.

PS.: If you want a folder accessible by both androidTest and test folders (say, a test fixtures folder called testShared), do the same process but also include a test { } block there:

android.sourceSets {
    test {
        java.srcDirs += "$projectDir/src/testShared"
    }

    androidTest {
        java.srcDirs += "$projectDir/src/testShared"
    }
}
like image 95
Rod Avatar answered Oct 14 '22 06:10

Rod