Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modularised Android testing - module test using base module test

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

like image 542
DmitryBorodin Avatar asked Nov 08 '22 08:11

DmitryBorodin


1 Answers

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.

like image 180
DmitryBorodin Avatar answered Nov 14 '22 21:11

DmitryBorodin