1. Unit Tests (Most)
ViewModels: The state and interaction logic of our pages.
Data Layers: Ensuring that data retrieval and storage processes are error-free.
Domain (useCases): These bridges between UI and data layers deserve attention because they contain crucial business logic.
2. Compose UI Tests (JVM – Robolectric)
Next, we’ll consider our UI tests. Instead of running these on a virtual emulator, we’re going to run them on the JVM using Robolectric. Doing so allows faster, more efficient testing. These tests will primarily cover interactions. We will test the response of the UI elements to user events, like the display of the error state or the functionality of clickable buttons.
3. Screenshot Tests (JVM – Robolectric)
Screenshot tests facilitate testing of larger page structures, allowing us to ensure that all UI components are placed and sized correctly. You can definitely do small composable-level screenshot tests with enough hands on deck. We’ll use Robolectric to run these tests on the JVM, addressing resource efficiency.
4. E2E UI Tests (Few, on Virtual Emulator)
Lastly, we’ll write e2e tests to cover user workflows. These tests simulate real user interactions from start to finish. For instance, a test might cover a user flow from login to completing an action. Despite running on a slower virtual emulator, these tests are indispensable for ensuring the seamless functionality of our app.
Overall, our strategy allows a broad coverage over the units, interface, and user flows, with efficient use of resources. Applying this comprehensive and efficient method, we can ensure a high-quality, reliable Android application. Feel free to adopt or adapt this strategy in your projects and share your experiences with us. Happy testing!