|
|
ADK Agent Test Doubles - Fakes, Mocks, and Stubs
Author: Venkata Sudhakar
ShopMax India's ADK agent test suite uses different kinds of test doubles to replace real dependencies: a stub returns a fixed response without caring how it is called, a mock verifies that the agent called a dependency in the expected way, and a fake is a lightweight working implementation of a real service. Choosing the right test double for each situation keeps tests fast, focused, and free from over-specification that breaks on harmless implementation changes.
In ADK agent testing: use stubs for read-only tool calls where the return value matters but the call count does not (e.g. order lookup); use mocks for write operations where the agent must call a specific method with specific arguments (e.g. sending a notification); use fakes for stateful services that need realistic behaviour across multiple calls (e.g. a session store or inventory cache). Spy objects record calls without changing behaviour - useful for logging assertions without breaking the real implementation.
The example below demonstrates all three test double types for ShopMax India: a stub for order lookup, a mock (call recorder) for the notification sender, and a fake for the inventory service. Each test uses the appropriate double for its verification goal.
It gives the following output,
... (3 passed in 0.01s)
In production, ShopMax India should document which test double type is used in each test module and why - this makes it easy for new engineers to extend the suite correctly. Prefer fakes over mocks for stateful dependencies like inventory because mocks that verify call arguments become brittle when the agent refactors its internal call sequence. Reserve mocks for side effects like emails and SMS where the exact call is the observable behaviour, not just the state change that results from it.
|
|