Your Cart
Loading

Test It Before They Do: Unit Tests, Coroutines and Flow, Compose UI Tests, Screenshot Tests and CI for Android Apps That Do Not Break on Release

On Sale
$19.00
$19.00
Added to cart

Test It Before They Do is a practical guide to the Android tests that catch bugs before your users do: the list that crashes when it is empty, the Save button that stays enabled while saving, the 401 that shows a stack trace instead of a sign-in screen, the dark mode that quietly broke, the half-written note lost when the system killed the app. It follows the test pyramid from the bottom up: fast ViewModel tests with coroutines and Flow on the JVM, network tests against a real HTTP server running inside the test, Jetpack Compose UI tests driven through the semantics tree, screenshot tests that catch the change you can see, and a small set of instrumented tests for what only a real Android system can show. Then it deals with the parts most guides skip: WorkManager, runtime permissions, process death, configuration changes and deep links; flaky tests and a quarantine policy; and a GitHub Actions workflow that runs everything on every pull request and blocks the merge while anything is red. Everything is applied to a small notes app, Field Notes, ending in its complete test suite. Every library version, API and Gradle task was checked against the official Android Developers pages and the projects' own release pages in October 2026, including the current state of Compose Preview Screenshot Testing (the standalone plugin is no longer maintained; the book uses the AGP 9.5 test-suite setup).

What you get

  • A test setup that works first time: source sets, a version catalog with current versions, Robolectric options, running one test from the command line and reading the reports
  • ViewModel tests: fakes vs mocks, MainDispatcherRule, runTest with StandardTestDispatcher and UnconfinedTestDispatcher, virtual time, Turbine for StateFlow, stateIn with backgroundScope, and SavedStateHandle
  • The network layer: OkHttp's MockWebServer (mockwebserver3), kotlinx.serialization edge cases, mapping every failure to one app error, Ktor's MockEngine, and an injected Clock
  • Compose UI tests: createComposeRule and createAndroidComposeRule, the merged and unmerged semantics trees, finders, assertions and actions, test tags and testTagsAsResourceId, synchronization and the main clock, navigation tests with TestNavHostController, and running it all on the JVM with Robolectric
  • Screenshot tests: Compose Preview Screenshot Testing on AGP test suites, Roborazzi, Paparazzi, reference images in Git, and keeping screenshots stable
  • Instrumented tests: Hilt test components with @TestInstallIn, @UninstallModules and @BindValue, Gradle Managed Devices and Automated Test Devices, the Test Orchestrator, Espresso interop and UI Automator for system dialogs
  • The hard parts: TestListenableWorkerBuilder and the WorkManager TestDriver, permission flows, StateRestorationTester and real process death, DeviceConfigurationOverride, deep links, and accessibility checks
  • Flaky tests: the usual causes and their fixes, a quarantine policy with a deadline, and why retries are the last resort
  • CI on GitHub Actions: a checks job, emulator tests with KVM via managed devices or android-emulator-runner, reports as artifacts, Kover coverage, and required status checks

75 pages, 22 diagrams plus a chapter-opener graphic for every chapter, a testing checklist and a cheat sheet. PDF and EPUB. Android the Right Way, Book 8.

Not sure yet? Read the free sample first: the cover, the full table of contents and all of Chapter 4, "Compose UI Tests" (the two test rules, the semantics tree and printToLog, finders, assertions and actions, a first screen test, testing a stateful composable, test tags and testTagsAsResourceId, synchronization and the test clock, navigation tests with TestNavHostController, running Compose tests on the JVM with Robolectric, and accessibility checks), at https://payhip.com/b/I905N


Also in a bundle: Everything Bundle: every ebook in the store, $89 ยท Android Bundle, $49.

You will get the following files:
  • PDF (3MB)
  • EPUB (4MB)