google/dagger

Hilt not working with android testFixtures?

Closed this issue · 2 comments

I have upgraded to AGP 8.5.0 which now supports Test Fixtures in Android modules (yay!).

I am now trying to declare my modules annotated with @TestInstallIn in the testFixtures source set so they can live next to the code they belong to, rather than being forced to create a separate module just for them.

However when using kaptTestFixtures with hilts android compiler, it seems as though its just plain ignoring whats on the test Fixtures source set.

I've created a small demo project that demonstrates the problem.

It's a very simple Compose app that I created Instrumented tests for, in the consuminglib module.

The androidlib module declares a PeopleService and a default implementation, which is bound in PeopleModule.

Within the androidlib module I put my FakePeopleService (which offers deterministic results, ideal for tests), and also my FakePeopleModule where I use @TestInstallIn to replace the module declared in the main source set.

However when running my test from consuminglib the binding is never replaced, nor do I see generated code being produced for testFixtures.

You'll find that in PeopleScreenTest some lines are commented out, those do work in replacing the binding with the fake implementation, which goes to prove that testFixtures does actually get properly imported.

Am I doing something wrong here?

According to https://issuetracker.google.com/issues/259523353#comment21

KAPT or KSP arent yet supported, so theres my answer.

Thanks for finding that, yea we'll need to wait for KAPT or KSP support before looking into this more. I'm going to close this for now, even though it is possible in the future once support is added we may have something to update on our side with our gradle plugin. But if that happens, we can always open an issue for it then. Thanks!