Víctor Albertos Víctor Albertos - 5 months ago 39
Android Question

Gradle multi project - sharing test code between modules

ProjectA
contains an abstract unit test,
TestA
.

ProjectB
has a test called
TestB
, which needs to extends from
TestA
, to fulfil the test requirements for this specific implementation.

I've added to the
build.gradle
configuration file on
ProjectB
,
ProjectA
as a dependency compilation test:

testCompile project(':ProjectA')


Also, as a dependency compilation:

compile project(':ProjectA')


Although I'm able to extend from
TestA
, when I try to run
TestB
I get the next error:

error: cannot find symbol class TestA


So, is there any way to share test code between modules?

Thanks.

Answer

As mentioned in this question you should add dependency on test sources like this:

compileTestJava.dependsOn tasks.getByPath(':projectA:testClasses')
testCompile files(project(':projectA').sourceSets.test.output.classesDir)
Comments