tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > ADK Agent Testing > Unit Testing ADK Agent Tools with pytest

Unit Testing ADK Agent Tools with pytest

Author: Venkata Sudhakar

ShopMax India's ADK agents rely on tool functions such as get_order_status and get_product_price to fetch live data during conversations. Unit testing these tools in isolation - before wiring them into the agent - catches bugs early, runs in milliseconds without an LLM call, and makes failures easy to diagnose. Pytest combined with unittest.mock lets you test every tool path without a real database or API.

Each ADK tool is a plain Python function. Unit tests call the function directly, passing mock dependencies as arguments instead of real database or catalog objects. The MagicMock class replaces the dependency and lets you control what it returns, so you can test both the happy path and edge cases like missing records without any external infrastructure.

The example below tests two ShopMax India ADK tools - get_order_status and get_product_price - covering found, not-found, and currency validation cases using pytest and MagicMock.


It gives the following output,

tests/test_tools.py::test_order_status_found PASSED
tests/test_tools.py::test_order_status_not_found PASSED
tests/test_tools.py::test_product_price_returns_rs_currency PASSED
tests/test_tools.py::test_product_price_missing_item PASSED

4 passed in 0.08s

In production, keep tool unit tests in a separate tests/unit/ folder so they can run in CI without credentials. Add parametrize decorators to cover multiple order IDs and product SKUs in a single test function. Run these tests on every pull request - a tool regression caught at unit level costs seconds to fix compared to catching it in a live agent conversation.


 
  


  
bl  br