how to access to test class from another module to use in junit test?

Viewed 892

I split current monolithic module to several modules: :app, :ui, :base.

I wrote test in :ui module using class from :base module.

class FooTest : BaseTest {

@Test
fun fooTest() {}
}

so BaseTest is in :base module but :ui module depends on :base. So AS shows to me that is is ok.

in gradle file for :ui module:

dependences {

   implementation project(":base")
}

But when test runs I get:

BaseTest: Unresolved reference: BaseTest

I tried to add:

   testImplementation project(":base")

or

   androidTestImplementation project(":base")

but not solve the problem. :(

1 Answers

This works if the BaseTest file is in the main directory of :base instead of the test directory

For example, you can have a module called commontest that contains common utils/classes that contain these in the main directory of the module and then to use it in other modules you can include it with testImplementation project(':commontest')

Related