Testing Strategy & Pyramid Interview Questions

TESTING › Strategy

What is the testing pyramid, and how does it apply to an Android app?

What a strong answer covers: Many fast unit tests at the base (ViewModels, use cases, repositories, mappers on the JVM), fewer integration tests in the middle (Room with an in-memory database, repository plus network with MockWebServer, Robolectric), and a small number of slow end-to-end UI tests on devices at the top for critical journeys. Each layer trades speed and isolation for realism.

What's your testing strategy for a new feature: unit, integration and UI?

What a strong answer covers: Unit test business logic and ViewModel state transitions with fakes; integration test the data layer (DAO queries, migrations, API parsing against recorded responses); screenshot or Compose UI test the screen's states; and one end-to-end test if it's a critical flow like checkout. Write tests for bug fixes first to reproduce them. A strong answer is specific about what is worth testing.

What's the difference between local tests and instrumented tests, and where does Robolectric fit?

What a strong answer covers: Local tests run on the JVM on your machine (src/test): fast, but no Android framework. Instrumented tests run on a device or emulator (src/androidTest): real framework, slow. Robolectric simulates the Android framework on the JVM, so tests touching Android classes can run locally, slower than pure JVM tests and not perfectly faithful.

How do you decide what not to test, and what does code coverage tell you and not tell you?

What a strong answer covers: Skip testing framework code, trivial getters, generated code and simple pass-through layers; focus on logic, edge cases and things that have broken before. Coverage shows which lines ran, not whether the assertions were meaningful: a test that calls everything and asserts nothing gets 100 percent. Use it to find untested areas rather than as a target, and look at mutation testing if you want to measure quality.

You join a team with no tests and a fragile app. How would you introduce testing without stopping feature work?

What a strong answer covers: Start where it pays: add tests with every bug fix, test new code as it's written, and add a few characterisation tests around the riskiest flows before refactoring them. Make testing easy: a CI job that runs tests on every pull request, shared fakes and test rules, and dependency injection so classes can be tested. Refactor gradually towards testable seams. Track flakiness, keep tests fast, and show value by catching regressions.

Back to Testing Strategy & Pyramid