tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > ADK Agent Testing > ADK Agent Test Fixtures and Factory Patterns

ADK Agent Test Fixtures and Factory Patterns

Author: Venkata Sudhakar

ShopMax India's ADK agent test suite spans order tracking, returns, EMI queries, and fraud detection - each requiring a consistent set of test data: sample orders, customer profiles, inventory records, and session state. Without fixtures and factories, each test file duplicates this setup code, causing drift when data schemas change. Centralising test data creation in pytest fixtures and factory functions keeps the suite maintainable and ensures every test starts from a known, valid state.

A pytest fixture creates reusable test state that is injected into test functions automatically. A factory function is a helper that builds test objects with sensible defaults but allows per-test overrides. Use fixtures for shared resources like a session store or tool registry, and factories for creating individual test entities like orders or customers. Parametrize fixtures to run the same test against multiple data scenarios without code duplication.

The example below defines fixtures and factories for ShopMax India's ADK agent tests: an order factory with defaults, a customer factory, a session store fixture, and a tool registry fixture. Tests use them to verify tool behaviour without repeating setup code.


It gives the following output,

... (3 passed in 0.01s)

In production, ShopMax India should version the factory defaults alongside the data schema so that when the order schema gains a new required field, all tests that use make_order() pick it up automatically without a grep-and-replace across the test suite. Keep factories in a shared conftest.py at the repo root so every test module can import them. Avoid fixtures that hit real external services - if a fixture needs database data, populate a local SQLite or mock backend instead.


 
  


  
bl  br