home / skills / dasien / claudemultiagenttemplate / test-design-patterns

test-design-patterns skill

/templates/.claude/skills/test-design-patterns

This skill helps you design robust tests by applying AAA, fixtures, and mocks to create maintainable, reliable Python test suites.

npx playbooks add skill dasien/claudemultiagenttemplate --skill test-design-patterns

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.5 KB
---
name: "Test Design Patterns"
description: "Apply testing patterns like AAA (Arrange-Act-Assert), mocking, fixtures, and parameterization for maintainable test suites"
category: "testing"
required_tools: ["Read", "Write", "Bash"]
---

# Test Design Patterns

## Purpose
Apply proven testing patterns to create maintainable, reliable test suites that effectively validate functionality.

## When to Use
- Writing unit, integration, or system tests
- Organizing test code
- Creating test fixtures and data
- Designing test strategies

## Key Capabilities
1. **AAA Pattern** - Arrange-Act-Assert structure
2. **Test Fixtures** - Reusable test data and setup
3. **Mocking/Stubbing** - Isolate units under test

## Approach
1. **Arrange**: Set up test data and conditions
2. **Act**: Execute the code being tested
3. **Assert**: Verify expected outcomes
4. Use descriptive test names
5. Keep tests independent and isolated

## Example
**Context**: Testing a task creation function
````python
def test_add_task_with_valid_input_creates_task():
    # Arrange
    queue = TaskQueue()
    task_data = {"title": "Test", "agent": "tester"}
    
    # Act
    task_id = queue.add_task(task_data)
    
    # Assert
    assert task_id is not None
    assert queue.get_task(task_id).title == "Test"
````

## Best Practices
- ✅ One logical assertion per test
- ✅ Descriptive test names explaining scenario
- ✅ Independent tests (no shared state)
- ❌ Avoid: Testing multiple unrelated things together

Overview

This skill teaches proven test design patterns to build maintainable, reliable Python test suites for multi-agent systems and automated workflows. It emphasizes clear structure, isolation, and reuse so tests remain readable and resilient as code evolves. The guidance targets unit, integration, and system tests for task queues, agents, and related components.

How this skill works

The skill inspects test scenarios and recommends patterns like Arrange-Act-Assert, fixtures, mocking/stubbing, and parameterization to organize test logic. It shows how to extract reusable setup into fixtures, replace external dependencies with mocks, and structure assertions for clarity. Practical examples demonstrate applying patterns to task creation, agent interactions, and queue operations.

When to use it

  • Writing new unit, integration, or system tests
  • Refactoring brittle or slow test suites
  • Creating reusable test fixtures and test data
  • Isolating external systems with mocks or stubs
  • Designing tests for multi-agent workflows and task queues

Best practices

  • Follow Arrange-Act-Assert to separate setup, execution, and verification
  • Use fixtures for shared setup and teardown to reduce duplication
  • Mock external services, I/O, and time-sensitive behavior to keep tests deterministic
  • Write one logical assertion per test and favor expressive, scenario-based names
  • Keep tests independent; avoid shared mutable state and inter-test order dependencies

Example use cases

  • Unit test a TaskQueue.add_task with AAA pattern and assert task properties
  • Use fixtures to provide pre-populated queues for integration tests of agent orchestration
  • Mock external HTTP calls from an agent to verify retry logic without network flakiness
  • Parameterize tests to cover multiple input shapes for task creation and validation
  • Refactor a brittle end-to-end test into smaller isolated tests with focused assertions

FAQ

How many assertions should a test include?

Aim for one logical assertion per test. You can have multiple assertions that verify different facets of the same behavior, but avoid testing unrelated outcomes in one test.

When should I use mocks vs fixtures?

Use fixtures for reusable setup and shared test data. Use mocks to replace external dependencies or side effects (network, I/O, time) so tests remain fast and deterministic.