Android test module dependencies

All,

Sometime back, I figured out how to create a dependency in one subproject on another subproject’s test sources. I found I could do the following in Gradle 4.x with a Java project:

dependencies {
    testCompile project(path: 'myOtherProject', configuration: 'tests')
}

I’m trying to do the same but with an Android Studio project that is using Gradle 5.1.1. My dependencies in this Android project look like:

dependencies {
    testImplementation project(path: ':anotherModule', configuration: 'testImplementation')
}

With this, I get a build error that says “Selected configuration ‘testImplementation’ on ‘project :anotherModule’ but it can’t be used as a project dependency because it isn’t intended for consumption by other components.”

I’m not sure if this is the right forum to ask this question, but why would this be disallowed? It seems perfectly reasonable that one module’s tests might have helper methods or test/stub data that another module might want to use in its tests. Is there some other way to achieve what I want? I see a few other discussions on this general topic but none with satisfying answers (mostly just workarounds that feel like hacks).

Any advice would be appreciated.

1 Like