tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK Testing Patterns and Unit Tests

ADK Testing Patterns and Unit Tests

Author: Venkata Sudhakar

Testing ADK agents requires testing at three layers: unit testing individual tool functions in isolation, integration testing the full agent via the runner, and evaluation testing response quality with expected-output assertions. Tool functions are plain Python and are the easiest to unit test with standard pytest. A failing tool unit test is trivially easy to debug; a failing agent evaluation test is much harder to diagnose. Always build the foundation of unit tests before relying on higher-level eval tests.

For tool unit tests, call the function directly with test inputs and assert the output dict. For agent integration tests, use Runner with InMemorySessionService, send a test message, and assert the response contains expected keywords. For state tests, pass a mock ToolContext and check state mutations. Run all tests in CI with pytest before every deployment � this is the quality gate that prevents regressions reaching production users.

The below example shows a complete test suite for a shopping cart agent: unit tests for each tool, an integration test for the full conversation, and a multi-turn state test verifying cart accumulation across turns.


Agent integration tests covering full conversation flow and multi-turn state,


It gives the following output when all tests pass,

$ pytest test_cart_agent.py -v

test_cart_agent.py::test_add_valid_product         PASSED
test_cart_agent.py::test_add_invalid_product       PASSED
test_cart_agent.py::test_add_duplicate_increments_qty PASSED
test_cart_agent.py::test_view_empty_cart           PASSED
test_cart_agent.py::test_view_cart_total           PASSED
test_cart_agent.py::test_checkout_clears_cart      PASSED
test_cart_agent.py::test_checkout_empty_cart       PASSED
test_cart_agent.py::test_agent_confirms_add        PASSED
test_cart_agent.py::test_agent_unknown_product     PASSED
test_cart_agent.py::test_agent_multi_turn_cart     PASSED

10 passed in 4.31s

# Tool tests run in milliseconds - no API calls needed
# Integration tests call the real Gemini API - run in CI with valid key
# Add to GitHub Actions: run on every push to main branch

Testing strategy for production ADK agents: write at least 5 unit tests per tool covering happy path, invalid input, boundary conditions, and state mutations. Write 3 to 5 integration tests covering the most common user flows, error handling, and multi-turn scenarios. Run tool unit tests on every git push (fast, cheap). Run integration tests only on merge to main (requires API key, costs tokens). Store test fixtures (sample inputs and expected outputs) in a JSON file so non-engineers can add new test cases without modifying code. Track test coverage over time and flag any new tool function that ships without unit tests in the CI pipeline.


 
  


  
bl  br