testing-patterns

TalkingMonkeyOz's avatarfrom TalkingMonkeyOz

Testing patterns and requirements for Claude Family projects

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 10, 2026

When & Why to Use This Skill

This Claude skill provides a comprehensive framework for implementing standardized testing patterns and requirements across software projects. It offers technical guidance for unit, integration, and regression testing in Python and TypeScript environments, while leveraging specialized AI agents to automate the creation of robust test suites, ensuring high code quality and reliability.

Use Cases

  • Automated Test Generation: Spawning 'tester-haiku' agents to automatically write unit tests for new functions, covering happy paths, edge cases, and error scenarios.
  • Standardizing Multi-Language Testing: Implementing consistent testing structures using pytest for Python projects and Jest or Vitest for TypeScript/web applications.
  • Database Testing & Isolation: Setting up isolated test databases with automated schema management and transaction rollback patterns to ensure side-effect-free validation.
  • Regression & E2E Testing: Orchestrating end-to-end web tests using Playwright and maintaining regression suites to prevent feature degradation during updates.
  • Pre-Commit Quality Assurance: Utilizing a structured checklist to verify unit tests, integration tests, and code coverage before committing code to the repository.
nametesting-patterns
descriptionTesting patterns and requirements for Claude Family projects
modelhaiku
agenttester-haiku

Testing Patterns Skill

Status: Active Last Updated: 2026-01-08


Overview

This skill provides testing patterns and requirements for Claude Family projects.


Per the Delegation Rules, consider spawning tester-haiku for test writing:

# Spawn tester agent to write tests for new code
mcp__orchestrator__spawn_agent(
    agent_type="tester-haiku",
    task="Write unit tests for the new functions in src/feature.ts. Cover happy path, edge cases, and error scenarios.",
    workspace_dir="C:/Projects/current-project"
)

# For E2E web tests, use web-tester-haiku
mcp__orchestrator__spawn_agent(
    agent_type="web-tester-haiku",
    task="Write Playwright E2E tests for the login flow.",
    workspace_dir="C:/Projects/current-project"
)

Test writing is structured work - Haiku agents handle it well and cheaply.


Quick Reference

Test Levels

Level Purpose When to Run
Unit Individual function/class Every change
Integration Component interactions Before commit
Regression Full feature coverage Before release
Smoke Critical paths only After deploy

Python Testing

Framework: pytest

# Run all tests
pytest tests/

# Run specific test file
pytest tests/test_feature.py

# Run with verbose output
pytest -v

# Run with coverage
pytest --cov=src tests/

Test Structure

# tests/test_feature.py
import pytest

class TestFeature:
    def setup_method(self):
        """Run before each test method"""
        pass
    
    def test_happy_path(self):
        """Test normal operation"""
        result = function_under_test(valid_input)
        assert result == expected_output
    
    def test_edge_case(self):
        """Test boundary conditions"""
        pass
    
    def test_error_handling(self):
        """Test error scenarios"""
        with pytest.raises(ValueError):
            function_under_test(invalid_input)

Fixtures

@pytest.fixture
def db_connection():
    """Provide test database connection"""
    conn = create_test_connection()
    yield conn
    conn.close()

def test_database_query(db_connection):
    result = db_connection.execute("SELECT 1")
    assert result is not None

TypeScript Testing

Framework: Jest or Vitest

# Jest
npm test

# Vitest
npx vitest

Test Structure

import { describe, it, expect, beforeEach } from 'vitest';

describe('Feature', () => {
  beforeEach(() => {
    // Setup
  });
  
  it('should handle normal input', () => {
    const result = functionUnderTest(validInput);
    expect(result).toBe(expectedOutput);
  });
  
  it('should throw on invalid input', () => {
    expect(() => functionUnderTest(invalidInput)).toThrow();
  });
});

Regression Testing

Claude Family Pattern

# scripts/run_regression_tests.py
def run_test(test_case):
    """Run single test case and return pass/fail"""
    try:
        result = execute_test(test_case)
        return result.success, result.message
    except Exception as e:
        return False, str(e)

def run_all_tests():
    """Run all regression tests"""
    results = []
    for test in TEST_CASES:
        passed, message = run_test(test)
        results.append((test.name, passed, message))
    return results

Database Testing

Test Database Pattern

@pytest.fixture(scope="session")
def test_db():
    """Create isolated test database"""
    # Create test schema
    conn = get_connection()
    conn.execute("CREATE SCHEMA IF NOT EXISTS test_claude")
    
    yield conn
    
    # Cleanup
    conn.execute("DROP SCHEMA test_claude CASCADE")

Data Validation Testing

def test_column_registry_enforcement():
    """Verify column constraints are enforced"""
    with pytest.raises(psycopg.errors.CheckViolation):
        insert_invalid_status_value()

Key Gotchas

1. Generic Constraints for Data Hooks

// WRONG: TypeScript interfaces fail Record constraint
function useTableSort<T extends Record<string, unknown>>(data: T[]) {}

// CORRECT: Use broader object constraint
function useTableSort<T extends object>(data: T[]) {}

2. Test Isolation

Always clean up after tests. Use transactions that rollback:

@pytest.fixture
def db_transaction(db_connection):
    with db_connection.transaction() as tx:
        yield tx
        tx.rollback()  # Always rollback

3. Async Testing

@pytest.mark.asyncio
async def test_async_function():
    result = await async_function()
    assert result is not None

Pre-Commit Checklist

Before committing code:

  • All unit tests pass
  • Integration tests pass
  • No new lint warnings
  • Coverage not decreased
  • Edge cases covered

  • database-operations - Database testing specifics
  • code-review - Review process includes test verification

Version: 1.1 (Added agent spawning guidance) Created: 2025-12-26 Updated: 2026-01-10 Location: .claude/skills/testing/skill.md