Skip to content

Hilt Testing and E2E tests #4599

@franciscoaleixo

Description

@franciscoaleixo

Our team would like to create E2E tests where the app should function as close to production as possible (even with backend). We realise this is inherently flaky but I'll leave that discussion for another day. We've figured we would use Hilt testing utils to inject some "interceptor-like" utils so that, for example, we could know what is coming from backend on our tests and check the corresponding behavior on our app.

Also, we'd like our test cases to be very self-contained, i.e. each test case should launch its own process / application, as we'd like to avoid sharing state across test cases and also avoid crashes in one test case spilling over to the rest. From what we've investigated, this seems to be possible with Android Test Orchestrator.

The issue now is that it doesn't seem like it is possible to accomplish this with @HiltAndroidTest. It looks like the application is always shared between test cases (even using Orchestrator) and the application is actually initialized before any test case. It is especially evident from the abundance of exceptions we've gotten trying to make this work (WorkManager/DataStore initializing twice as they are rebound each test case, etc.). We also realize this is expected and well documented.

Regardless, I guess my question is: is there any way to make Hilt testing work with Android Test Orchestrator and make these self-contained test cases possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions