1 / 11
Learn to test a real Android app at every layer: JUnit 4 and JUnit 6, test doubles and MockK, coroutines and virtual time, Flow with Turbine, ViewModels, Room and migrations, DataStore, MockWebServer, offline-first repositories, WorkManager, Robolectric, Compose UI tests, Roborazzi screenshot…
Unit, Integration, Compose UI, Screenshot, and End-to-End Tests That Keep a Real App Shippable
Read before you buy: the PDF here is a free sample — the first 20 pages of the 459-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
Build a fast, trustworthy Android test suite — and the confidence to ship every week.
Every Android team reaches the point where nobody is sure what a change will break. Releases slow down, fixed bugs come back, and the refactoring everyone wants never happens. A good test suite is the way out: one that runs in minutes, fails only when something is really wrong, and tells you exactly what broke.
This book teaches you to build that suite step by step. You start with plain JUnit tests and work outward through every layer of a modern Kotlin and Jetpack Compose app, learning not just the APIs but where each kind of test belongs and why.
What's inside
- The test pyramid for Android, local versus instrumented tests, and a practical strategy for what to test where
- JUnit on Android today: JUnit 4, JUnit 6 Jupiter, the Vintage engine, and exactly what runs where
- Readable tests: naming, Arrange-Act-Assert, test data builders, Gradle test fixtures, and clear failure messages
- Test doubles done right: fakes, stubs, spies, and mocks, plus MockK without over-mocking
- Coroutines with runTest, test dispatchers, and virtual time; Flow and StateFlow with Turbine; ViewModels with SavedStateHandle
- Room DAOs, type converters, and migration tests; DataStore and file storage; Retrofit and OkHttp against MockWebServer with JSON fixtures
- Integration tests for offline-first repositories, and WorkManager workers with retries and constraints
- Robolectric for Android framework code on the JVM, and Compose UI testing through semantics, finders, the test clock, and idling
- Screenshot testing with Roborazzi (record, verify, compare), and how Paparazzi fits in
- Accessibility, dark theme, locales, font scale, and screen-size coverage without a test explosion
- Hilt testing with replaced modules, instrumented tests with Espresso and Compose, UI Automator end-to-end tests, Gradle Managed Devices, and Test Orchestrator
- Flaky tests (causes, diagnosis, quarantine, cures), coverage with Kover and JaCoCo, a CI test strategy with GitHub Actions, and bringing legacy code under test
One running example, start to finish. You test Waypoint, a fictional hiking trip planner from the fictional studio Northbeam Labs: trail search with an offline cache, trip planning with real business rules, a Retrofit API, a Room database, a WorkManager sync worker, and Compose screens. Starting from a modular starter project, you grow its suite chapter by chapter into a complete testing strategy — fast local tests on every pull request, screenshot tests that catch visual regressions, Hilt-powered app tests, and device tests for the journeys that matter most.
Current and honest. The book uses a recent toolchain — Android Gradle Plugin 9, Kotlin 2.4, JDK 21, the 2026 Compose BOM, Robolectric 4.17, Roborazzi, Kover, and JUnit 6 — and every local test was run on it. Tests that need a device are clearly marked, and their output is shown as "similar to" what you will see. There are no invented benchmarks or statistics. Every chapter includes complete code, Tips, Notes, Warnings, exercises, and Key Takeaways, and the appendices give you a cheat sheet, copy-ready templates, a test suite production checklist, and a glossary.
Format: PDF, 459 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. Includes the Waypoint starter project (Gradle, Kotlin) used throughout the book. Requires JDK 21 and the Android SDK (Android Studio recommended) to build the code. This book is independent and is not affiliated with, sponsored by, or endorsed by Google LLC or any other company mentioned.
Table of Contents
Part I — Foundations
- Ch 1 · Why Test Android Apps: The Testing Pyramid, Test Types, and Waypoint
- Ch 2 · Your First Local Tests: JUnit 4, Assertions, and Running Tests with Gradle
- Ch 3 · JUnit on Android Today: JUnit 4, JUnit 6 Jupiter, the Vintage Engine, and What Runs Where
- Ch 4 · Writing Good Tests: Naming, Arrange-Act-Assert, Test Data Builders, and Clear Failures
- Ch 5 · Testing Pure Kotlin: Domain Rules, Edge Cases, Time, and Parameterized Tests
Part II — Test Doubles and Asynchronous Code
- Ch 6 · Test Doubles: Fakes, Stubs, Spies, and Mocks — and When to Use Each
- Ch 7 · Mocking with MockK: Stubbing, Verification, Slots, and Pitfalls
- Ch 8 · Testing Coroutines: runTest, Test Dispatchers, and Virtual Time
- Ch 9 · Testing Flow and StateFlow with Turbine
- Ch 10 · Testing ViewModels: UI State, SavedStateHandle, Errors, and Events
Part III — Data and Integration
- Ch 11 · Testing Room: In-Memory Databases, DAOs, Converters, and Migrations
- Ch 12 · Testing DataStore, Files, and Other Local Storage
- Ch 13 · Networking Tests with MockWebServer: Retrofit, OkHttp, JSON Fixtures, and Failures
- Ch 14 · Integration Tests for Repositories and Offline-First Sync
- Ch 15 · Testing WorkManager: Workers, Factories, Retries, and Constraints
Part IV — UI and Screenshot Testing
- Ch 16 · Robolectric: Android Framework Tests on the JVM
- Ch 17 · Compose UI Testing Fundamentals: Semantics, Finders, Assertions, and Actions
- Ch 18 · Compose UI Testing in Depth: Synchronization, Idling, Lists, and Navigation
- Ch 19 · Screenshot Testing with Roborazzi (and Where Paparazzi Fits)
- Ch 20 · Accessibility, Themes, Locales, Font Scale, and Screen Sizes
Part V — Hilt, Instrumented, and End-to-End Tests
- Ch 21 · Dependency Injection in Tests: Hilt Testing and Replacing Modules
- Ch 22 · Instrumented Tests: AndroidJUnitRunner, Espresso, and Compose on a Device
- Ch 23 · End-to-End Tests with UI Automator
- Ch 24 · Gradle Managed Devices, Test Orchestrator, and Sharding
Part VI — Test Suite Quality and CI
- Ch 25 · Flaky Tests: Causes, Diagnosis, Quarantine, and Cures
- Ch 26 · Code Coverage with Kover and JaCoCo: Measuring What Matters
- Ch 27 · A CI Test Strategy: Gradle Tasks, GitHub Actions, Caching, and Reports
- Ch 28 · Testing Legacy Code and Case Study: Waypoint's Complete Test Strategy
Appendices
A · Android Testing Cheat Sheet
B · Templates and Reference
C · Test Suite Production Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 459 |
| Format | PDF (A4) + Waypoint starter project (Gradle) |
| Language | English |
| Level | Intermediate |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
ไฟล์ที่คุณจะได้รับ
ยังไม่มีรีวิว เฉพาะผู้ซื้อเท่านั้นที่รีวิวได้
สินค้าอื่นจาก thenexbooks