10

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.

Víctor Albertos
  • 7,715
  • 5
  • 39
  • 68

1 Answers1

4

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)
Community
  • 1
  • 1
tkachuko
  • 1,904
  • 12
  • 19
  • Can you give an example for how to do this for `androidTest`s with kotlin? – B W Apr 25 '18 at 21:30
  • This is incorrect: 1) The second line implies the first; you don't need both. 2) This will result in the tests from projectA also being run in this project – David Nelson Jul 24 '18 at 14:44