Víctor Albertos
Víctor Albertos

Reputation: 8293

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.

Upvotes: 10

Views: 6379

Answers (1)

tkachuko
tkachuko

Reputation: 1986

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)

Upvotes: 4

Related Questions