Fakes over mocks

A fake is a second, simpler implementation β€” not a script of expectations

Module 15 introduced WalkerRepository as an interface, injected via Hilt. A mock is a generated stand-in that plays back a scripted expectation β€” "when getWalkers() is called, return this list" β€” and can fail a test for reasons that have nothing to do with the behavior you actually care about, like calling a method one extra time.

A fake is different: it's a small, real class that implements the same interface with real (if simplified) behavior β€” an in-memory list instead of a network call β€” and returns canned data because that's genuinely what it does, not because it was told to expect a call. Fakes are more robust than mocks precisely because there's no expectation script to break; the test just asks the fake what it returns, the same way it would ask the real thing.

In a Hilt-based app, swapping a fake in for tests is exactly what module 15's @Module/@InstallIn pattern is for: a test-only Hilt module binds WalkerRepository to the fake instead of the real network-backed implementation, so anything under test that injects the interface gets the fake without changing a line of production code.