5

I'm trying to get the Gradle Java plugin to execute jUnit tests that exist in an Android project. My solution was to create a second module that applies the Java plugin, and set the test sourceSet to the app module's src/test directory.

test-module's build.gradle:

apply plugin: 'java'
...
dependencies {
    ...
    testCompile project(':app-module')
}
sourceSets {
    test {
        java.srcDirs += ["${appDir}/src/test/java"]
    }
}

This works fine from the command line, but Android Studio refuses to import a project that has source sets outside the submodule. It throws the error: Can't register given path of type 'TEST' because it's out of content root.

.
├── app-module
│   ├── build.gradle
│   └── src
│       ├── main
│       └── test
├── test-module
│   └── build.gradle
├── build.gradle
└── settings.gradle

I tried configuring this from the parent build.gradle, but that didn't change anything. I can add app-module as a testCompile project dependency in test-module, but that doesn't cause test-module to add app-module's tests.

Any ideas for getting test-module to run app-module's tests without provoking Android Studio's limitation about remote source sets?

Turnsole
  • 3,422
  • 5
  • 30
  • 52

0 Answers0