Android multi module test dependency

Let’s say I have two android modules

module-base
module-a

When I want to access sources from module-base in module-a , I just need to write this in my
module-a.gradle

dependencies {
implementation project(path: ':module-base')
}

But, what if I want to access test sources from module-base in test of module-a?
Here does not work approach like above

dependencies {
testImplementation project(path: ':module-base')
}

I found lot of advices (few years old) which says something like

    compileTestJava.dependsOn tasks.getByPath(':module-base:testClasses')
    testCompile files(project(':module-base').sourceSets.test.output.classesDir)

or
testCompile project(':module-base).sourceSets.test.classes

But no one from mentioned works. There is always something wrong from the compiler point of view :-/

Can you someone help me how to create Android test code dependency between two modules?

1 Like

I am trying to get past the same problem. Have you tried the jar based setup mentioned in this SO answer - https://stackoverflow.com/a/5153162/3811963 . This has been working for me while using Android Gradle Plugin 2.x. Though recently the same setup has not worked for me with AGP 3.0. So I am looking for alternate solutions to this problem as well.

My workaround for that is here: https://github.com/kotomisak/image-analyzer-android