Testing fundamentals
Testing Fundamentals Deep Dive¶
Overview¶
Testing strategy should maximize confidence per minute of execution and maintenance cost.
Core Concepts¶
- Fast, deterministic tests close to business logic.
- Fewer but meaningful integration tests.
- Selective UI and end-to-end tests for critical journeys.
Test Pyramid and Strategy¶
- Unit tests: broad coverage, low runtime cost.
- Integration tests: boundary correctness.
- UI/E2E tests: user-critical flows only.
Tooling and Infrastructure¶
- JUnit + coroutine test APIs.
- MockWebServer for network determinism.
- CI sharding for parallel execution.
Flaky Test Mitigation¶
- Eliminate timing assumptions.
- Replace real clocks and dispatchers.
- Isolate shared mutable test state.
Code Examples¶
@Test
fun repository_returnsCachedValueBeforeNetwork() {
// Arrange
// Act
// Assert
}
Common Interview Questions¶
- Q: How do you pick the right test layer? A: Answer by test pyramid intent: unit for logic speed, integration for boundaries, and end-to-end for critical journeys with flakiness controls.
- Q: What makes a suite trustworthy? A: Answer by test pyramid intent: unit for logic speed, integration for boundaries, and end-to-end for critical journeys with flakiness controls.
- Q: How do you reduce flaky runs? A: Answer by test pyramid intent: unit for logic speed, integration for boundaries, and end-to-end for critical journeys with flakiness controls.
Production Considerations¶
- Test failures should be actionable.
- Keep test runtime budgets for CI.
Performance Insights¶
- Prioritize test parallelism and hermetic setup.
Senior-Level Insights¶
- Strong strategy balances speed, reliability, and maintainability.