This page provides practical guidance for testing ADK agents, tools, and services. It covers unit testing, integration testing, and ADK-specific testing patterns to help developers maintain code quality and prevent regressions.
For information about the formal evaluation framework (EvalSet, EvalCase, metrics), see Evaluation Framework. For details on evaluation metrics, see Evaluation Metrics. For conformance testing capabilities, see Conformance Testing.
ADK testing follows a multi-layered approach:
Sources: CONTRIBUTING.md79-126 README.md173-186
ADK uses pytest as the testing framework. Unit tests are located under tests/unittests/ following existing naming conventions.
Key Requirements:
Sources: CONTRIBUTING.md84-101
Sources: CONTRIBUTING.md173-186 README.md173-178
When testing agents, focus on isolating the agent logic from LLM calls and service dependencies:
Testing Patterns:
Sources: CONTRIBUTING.md89-101
Tools should be tested independently from agents:
| Test Aspect | What to Test | Example |
|---|---|---|
| Execution | Tool executes successfully with valid inputs | Tool returns expected result |
| Input Validation | Tool handles invalid inputs gracefully | Raises appropriate errors |
| Authentication | OAuth2 flows work correctly | Credential exchange succeeds |
| Confirmation | Confirmation flow triggers when required | User approval requested |
| Error Handling | Tool handles failures and timeouts | Returns error information |
| Tool Context | ToolContext provides session access | State read/write works |
Sources: CONTRIBUTING.md89-101 src/google/adk/tools/base_tool.py (not provided but referenced)
Service implementations should be tested with focus on data persistence and retrieval:
Testing Considerations:
Sources: CONTRIBUTING.md89-101
Best Practices:
InMemorySessionService and InMemoryArtifactService for testingmock_tool_output in eval casesSources: CONTRIBUTING.md96-99 src/google/adk/evaluation/evaluation_constants.py25
The development UI provides interactive testing capabilities:
Testing Steps:
adk web path/to/agentSources: CONTRIBUTING.md110-116 README.md134-138
The Runner class enables programmatic testing of complete agent workflows:
Example Testing Flow:
Runner with agent and configurationSources: CONTRIBUTING.md117-124
Testing Workflow:
Sources: CONTRIBUTING.md202-229
ADK extensively uses async/await patterns. Test async code properly:
Best Practices:
@pytest.mark.asyncioawait coroutinesasync for to iterate event streamsasyncio.gather()Test your agent with multiple service implementations to ensure portability:
| Service | Test With | Purpose |
|---|---|---|
| Session | InMemorySessionService | Fast unit tests |
| Session | DatabaseSessionService (SQLite) | Persistence testing |
| Artifact | InMemoryArtifactService | Fast unit tests |
| Artifact | FileArtifactService | Local file storage |
| Memory | InMemoryMemoryService | Fast unit tests |
Testing Pattern:
Sources: CONTRIBUTING.md89-101
Test human-in-the-loop (HITL) confirmation scenarios:
Test Considerations:
ConfirmationRequestEvent is emittedSources: README.md49
Testing code that integrates with LLMs requires special considerations:
Best Practices:
Naming Conventions:
test_<module>_<feature>.pyTest<Feature>test_<scenario>()Sources: CONTRIBUTING.md93-94
Coverage Requirements:
Sources: CONTRIBUTING.md90-92
CI Pipeline:
Sources: README.md5 CONTRIBUTING.md190-194
Before submitting a PR:
Sources: CONTRIBUTING.md187-194
| Category | Requirement | Status |
|---|---|---|
| Unit Tests | Added/updated unit tests | ☐ |
| Unit Tests | All tests pass locally | ☐ |
| Coverage | New code has test coverage | ☐ |
| E2E Testing | Manual E2E testing completed | ☐ |
| E2E Testing | Screenshots/logs provided | ☐ |
| Documentation | Test plan described in PR | ☐ |
| Code Quality | Code formatted (autoformat.sh) | ☐ |
| Build | Wheel builds successfully | ☐ |
Sources: .github/pull_request_template.md22-48
For each PR, include a testing plan:
Sources: .github/pull_request_template.md22-38
What Not To Do:
Sources: CONTRIBUTING.md96-99
Effective testing in ADK requires:
By following these best practices, you ensure that your ADK agents are reliable, maintainable, and production-ready.
Sources: CONTRIBUTING.md79-126 README.md142-146
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.