Testing Agent-Written Android Code

← Back to Blog & Articles

Tests are the strongest safety net for agent output, but only if they test real behavior and are trusted.

Let tests drive the work

Ask the agent to write failing tests first, or to run an existing suite after each change. A passing test gives concrete evidence, and a failing one gives the agent actionable feedback.

Watch for weak tests

Agents sometimes write tests that merely restate the implementation, assert nothing meaningful, or pass because they mock away the behavior under test. Review tests as carefully as production code.

Layers of testing

  • Unit tests for logic in view models and repositories, using fakes for dependencies.
  • UI tests for Compose screens and key user flows.
  • Integration tests for data layers, including database migrations.
  • Screenshot tests to catch unintended visual changes.

Protect the tests

Prevent an agent from "fixing" a failing build by deleting or weakening tests. Require human approval for changes to test files or CI configuration.

Measure what matters

Coverage numbers can be gamed. Complement them with mutation testing or manual spot checks of important behavior.

Keep it fast

Slow suites will not be run. Provide quick targeted commands so the agent can verify each small change.

Takeaway

Treat tests as the specification the agent must satisfy, and make sure the specification itself is sound.

Continue with the book

Explore the full treatment, worked examples, and exercises in Agentic Android App Development.


Adapted from Agentic Android App Development, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top