Test

Create comprehensive tests for implemented features and validate they pass.

mhmdez updated 5mo ago
Claude CodeGeneric
View source ↗
# /test - Create and run tests

Create comprehensive tests for implemented features and validate they pass.

## Metadata

```yaml
allowed-tools: [Read, Glob, Grep, Bash, Write, Edit, TodoWrite]
description: Create and run tests
model: sonnet

Purpose

Create unit tests, integration tests, and validation scripts for completed implementations. Ensure all tests pass before proceeding to code review. This phase focuses on test coverage, edge cases, and validation.

When to Use

  • After completing implementation with /implement
  • When a feature needs test coverage
  • Following SDLC workflow after implementation phase
  • For validating bug fixes with regression tests

Input

$ARGUMENTS - Spec file path, task description, or empty for most recent implementation

  • Spec file: specs/feature-name.md
  • Task description: "Test user authentication"
  • Empty: Tests the most recently implemented feature

Process

1. Load Implementation Context

  • Read the spec file from specs/ (if available)
  • Identify files created/modified in implementation
  • Understand the feature's requirements and acceptance criteria
  • Review any existing test patterns in the codebase
  • Note testing framework and conventions used

2. Analyze Test Requirements

Determine what needs testing:

From Spec:

  • Review "Testing Plan" section if present
  • Identify unit test cases listed
  • Note integration scenarios
  • Find edge cases to cover

From Implementation:

  • Public APIs and functions
  • Class methods and properties
  • Error handling paths
  • Edge cases and boundaries
  • Integration points

3. Create Todo List

Use TodoWrite to track test creation:

  • Unit tests for each module/component
  • Integration tests for workflows
  • Edge case coverage
  • Test execution and validation
  • Mark initial task as in_progress

4. Understand Testing Patterns

Before writing tests, explore existing test structure:

# Find existing tests
ls tests/

# Check test patterns

Use Read/Glob to understand:

  • Test file naming conventions (test_*.py, *_test.py, etc.)
  • Testing framework (pytest, unittest, etc.)
  • Fixture patterns and helpers
  • Assertion styles
  • Mock/stub approaches

5. Write Tests

Create tests following project conventions:

Unit Tests:

  • Test individual functions and methods
  • Mock external dependencies
  • Cover normal cases, edge cases, and errors
  • Use descriptive test names
  • Keep tests focused and isolated

Integration Tests:

  • Test component interactions
  • Use real dependencies where appropriate
  • Test end-to-end scenarios
  • Validate data flow

Test Organization:

# tests/test_feature/test_module.py

def test_function_normal_case():
    """Test function with valid input."""
    result = function(valid_input)
    assert result == expected_output

def test_function_edge_case():
    """Test function with edge case input."""
    result = function(edge_case_input)
    assert result == expected_edge_output

def test_function_error_handling():
    """Test function raises appropriate error."""
    with pytest.raises(ExpectedError):
        function(invalid_input)

Coverage Goals:

  • All public functions tested
  • All error paths tested
  • All edge cases covered
  • Critical integration points validated

6. Run Tests

Execute test suite and verify all pass:

# Run tests based on project setup
pytest tests/                    # Python
npm test                         # Node.js
cargo test                       # Rust
go test ./...                    # Go

# With coverage
pytest --cov=src --cov-report=term

# Specific test file
pytest tests/test_feature/test_module.py

Validation:

  • All new tests pass
  • No existing tests broken
  • Coverage meets requirements
  • No flaky tests
  • Performance acceptable

7. Fix Failures

If tests fail:

Implementation Issues:

  • Fix the implementation code
  • Re-run tests to verify fix
  • Document what was wrong

Test Issues:

  • Correct test expectations
  • Fix mock setup
  • Adjust assertions
  • Update test data

Keep iterating until all tests pass.

8. Output Summary

Report:

  • Test files created (with paths)
  • Number of tests added
  • Coverage metrics (if available)
  • Test execution results
  • Any failures fixed
  • Next steps (should be "/review")

Example Usage

/test specs/user-authentication.md

Creates tests based on the spec's testing plan.
/test Validate user profile editing

Searches for matching spec and creates tests.
/test

Tests the most recently implemented feature.

Response Format

Tests created and validated: {feature name}

Test Files Created:
- tests/test_feature/test_module.py - {N} unit tests
- tests/test_feature/test_integration.py - {N} integration tests

Test Results:
✅ {N} tests passed
Coverage: {X}%

Test Highlights:
- {Key test scenario}
- {Edge case covered}
- {Integration validated}

All tests passing.

Next: Run `/review` for code quality review

Notes

  • Model: Use Sonnet for test creation (sufficient for most testing tasks)
  • Coverage: Aim for high coverage of new code, not 100% of everything
  • Patterns: Follow existing test conventions in the codebase
  • Isolation: Unit tests should be fast and isolated
  • Clarity: Test names should clearly describe what is being tested
  • Fixtures: Reuse fixtures and helpers from existing tests
  • Mocking: Mock external dependencies (APIs, databases, filesystem)
  • Assertions: Use clear, specific assertions
  • Documentation: Tests serve as documentation - make them readable

Anti-Patterns

Avoid these common mistakes:

  • Don't: Write tests that don't actually test anything Do: Assert specific, meaningful outcomes

  • Don't: Test implementation details Do: Test public interfaces and behavior

  • Don't: Create brittle tests that break on minor changes Do: Test behavior, not exact output format

  • Don't: Skip edge cases and error pat


Maintain Test?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Test on getagentictools](https://getagentictools.com/loops/mhmdez-test-create-and-run-tests?ref=badge)
npx agentictools info loops/mhmdez-test-create-and-run-tests

The second line is the CLI lookup for this page — handy in READMEs and docs.