What if your tests could run instantly and never fail because of slow or missing data?
Why Repository testing with fakes in Android Kotlin? - Purpose & Use Cases
Imagine you want to test your app's data fetching, but it depends on a real database or a web service that is slow or sometimes unavailable.
You try to run tests, but they fail or take forever because they rely on these real parts.
Running tests with real databases or network calls is slow and flaky.
It can cause tests to fail randomly due to network issues or data changes.
This makes it hard to trust your tests and slows down your development.
Using fakes means creating simple, pretend versions of your data sources.
These fakes behave like the real ones but are fast and reliable.
This lets you test your repository logic quickly and safely without real dependencies.
val data = realDatabase.getData() assert(data.isNotEmpty())
val fakeDb = FakeDatabase() val data = fakeDb.getData() assert(data.isNotEmpty())
It enables fast, reliable tests that focus on your app's logic, not on external systems.
When building a weather app, you can fake the weather API to return fixed data, so your tests never fail due to network problems.
Manual tests with real data sources are slow and unreliable.
Fakes simulate data sources for fast and stable tests.
This improves confidence and speed in app development.