5

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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.