I have a android project with multiple modules, module B that depends on module A
dependencies {
implementation project(':features:A')
}
I want unit test in module B to extend base test from module A. An IDE resolved all dependencies successfully, but in build time only production code from module A is accessable in test.
I tried to add dependency specificly for tests:
dependencies {
testCompile project(':features:A').sourceSets.test.output
}
This results an error:
Could not get unknown property 'test' for SourceSet container of type org.gradle.api.internal.tasks.DefaultSourceSetContainer.
Same if I'm trying to create custom artifact with tests.
How can I get access to test-specific code in base module from dependent module?
AS 3.1, gradle 4.1
The best solution I found is to create third module just for tests, put my base test classes and test dependencies there. And use it in both module A and module B (and all other modules - just one module for all unit test dependencies)
testImplementation project(':features:basetests')
Disadvantage - it is possible to import it in non-test artifacts (e.q. implementation project(':features:basetests')). Good code review can protect from such mistakes. Looks like there is no convenient way to define base shared test-only code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With