test-writing

Defines patterns for writing tests, including subsection tests for incremental development and acceptance criteria verification. Use when writing any tests to ensure consistent naming, structure, and coverage patterns.

13 stars

Best use case

test-writing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Defines patterns for writing tests, including subsection tests for incremental development and acceptance criteria verification. Use when writing any tests to ensure consistent naming, structure, and coverage patterns.

Teams using test-writing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/test-writing/SKILL.md --create-dirs "https://raw.githubusercontent.com/arun-gupta/agentic-tictactoe/main/.claude/skills/test-writing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/test-writing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How test-writing Compares

Feature / Agenttest-writingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Defines patterns for writing tests, including subsection tests for incremental development and acceptance criteria verification. Use when writing any tests to ensure consistent naming, structure, and coverage patterns.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Test Writing Pattern

This skill defines how to write tests following established patterns and best practices.

## Test Structure

### File Organization

- Unit tests: `tests/unit/<module>/test_<component>.py`
- Integration tests: `tests/integration/test_<feature>.py`
- API tests: `tests/integration/api/test_api_<endpoint>.py`

### Test Class Structure

```python
"""Tests for <component>: <description>.

Tests verify:
- <key requirement 1>
- <key requirement 2>
- <key requirement 3>
"""

import pytest
from <appropriate imports>

@pytest.fixture
def <fixture_name>():
    """Fixture description."""
    # Setup
    yield <value>
    # Cleanup (if needed)


class Test<ComponentName>:
    """Test <component>: <description>."""

    def test_feature_description(self, fixture) -> None:
        """Test specific feature requirement."""
        # Arrange
        # Act
        # Assert
```

## Naming Conventions

### Subsection Tests

For incremental development during phase implementation:

```python
def test_subsection_X_Y_Z_requirement_description(self) -> None:
    """Test subsection X.Y.Z requirement."""
```

Examples:
- `test_subsection_1_2_3_validates_input_bounds`
- `test_subsection_2_1_1_returns_200_with_healthy_status`
- `test_subsection_3_2_1_enforces_timeout`

### Acceptance Criteria Tests

For official verification (AC-X.Y.Z format):

```python
def test_ac_X_Y_Z_requirement_description(self) -> None:
    """Test AC-X.Y.Z: requirement description."""
```

Examples:
- `test_ac_2_1_1_returns_200_with_health_status`
- `test_ac_3_2_1_response_completes_within_100ms`

### General Tests

For other test cases:

```python
def test_feature_description(self) -> None:
    """Test that feature works correctly."""
```

## Type Annotations

**Always** include return type annotations:

```python
def test_something(self) -> None:
    """Test description."""
    pass
```

## Test Patterns

### Unit Tests

Test individual components in isolation:

```python
def test_component_behavior(self) -> None:
    """Test component does X."""
    # Create component
    component = Component()

    # Call method
    result = component.method()

    # Assert behavior
    assert result.expected_property == expected_value
```

### Integration Tests

Test interactions between components:

```python
@pytest.fixture
def service():
    """Create service for testing."""
    return Service()

def test_service_pipeline_integration(self, service) -> None:
    """Test full service pipeline."""
    # Set up test data
    test_data = create_test_data()

    # Run pipeline
    result = service.process(test_data)

    # Verify result
    assert result.success is True
    assert result.data is not None
```

### API Tests

Test FastAPI endpoints:

```python
from fastapi.testclient import TestClient

@pytest.fixture
def client():
    """Create test client."""
    return TestClient(app)

def test_get_endpoint_returns_200(self, client: TestClient) -> None:
    """Test GET endpoint returns 200."""
    response = client.get("/endpoint")

    assert response.status_code == 200
    data = response.json()
    assert data["expected_field"] == expected_value
```

## Assertion Patterns

### Success Cases

```python
assert result.success is True
assert result.data is not None
assert result.data.expected_property == expected_value
```

### Error Cases

```python
assert result.success is False
assert result.error_code == "E_ERROR_CODE"
assert result.error_message is not None
```

### Status Codes

```python
assert response.status_code == 200  # Success
assert response.status_code == 400  # Bad Request
assert response.status_code == 404  # Not Found
assert response.status_code == 500  # Internal Error
assert response.status_code == 503  # Service Unavailable
```

## Fixtures

### Common Fixtures

```python
@pytest.fixture
def sample_data():
    """Create sample test data."""
    return {
        "id": "test-id",
        "name": "Test Item",
        "status": "active"
    }

@pytest.fixture
def service():
    """Create service instance."""
    return Service()
```

### Autouse Fixtures

For setup/teardown needed for all tests:

```python
@pytest.fixture(autouse=True)
def reset_state():
    """Reset state before each test."""
    # Setup
    yield
    # Cleanup
```

## Test Coverage Requirements

### Core Business Logic

- **Target**: 100% coverage
- Test all validators
- Test all edge cases
- Test model creation and serialization
- Test state transitions

### Service Layer

- **Target**: ≥90% coverage
- Test each service in isolation
- Test service integration
- Test timeout mechanisms
- Test error handling

### API Endpoints

- **Target**: ≥80% coverage
- Test all endpoints
- Test success and error cases
- Test request/response models
- Test error code mapping

### UI Components

- **Target**: ≥70% coverage
- Test component rendering
- Test user interactions
- Test state management
- Test error boundaries

## Best Practices

1. **Descriptive names**: Test names should clearly describe what is tested
2. **One assertion per concept**: Group related assertions, but test one concept per test
3. **Arrange-Act-Assert**: Structure tests clearly
4. **Use fixtures**: Avoid code duplication with fixtures
5. **Test edge cases**: Include boundary conditions and error cases
6. **Test independently**: Tests should not depend on execution order
7. **Verify acceptance criteria**: Ensure AC-X.Y.Z requirements are met

## Common Edge Cases

### Testing Error Codes

```python
def test_returns_correct_error_code(self) -> None:
    """Test returns correct error code."""
    result = component.method(invalid_input)

    assert result.success is False
    assert result.error_code == "E_ERROR_CODE"
```

### Testing Timeouts

```python
def test_enforces_timeout(self) -> None:
    """Test timeout is enforced."""
    start_time = time.time()
    result = slow_operation()
    elapsed_time = time.time() - start_time

    assert result.error_code == "E_TIMEOUT"
    # Note: Don't assert exact timing, just that timeout occurred
```

### Testing State Changes

```python
def test_updates_state_correctly(self) -> None:
    """Test state is updated correctly."""
    initial_state = get_state()

    operation()

    updated_state = get_state()
    assert updated_state.property != initial_state.property
```

Related Skills

subsection-implementation

13
from arun-gupta/agentic-tictactoe

Complete workflow for implementing a single subsection from the implementation plan. Orchestrates all project skills to ensure consistent, high-quality implementation with full test coverage. Use when implementing any subsection (e.g., 5.1.1, 5.2.3) to automate the entire workflow from requirements to commit.

si

13
from arun-gupta/agentic-tictactoe

Short alias for /subsection-implementation. Implements a single subsection from docs/implementation-plan.md with full automation. Usage: /si 5.1.1

pre-commit-validation

13
from arun-gupta/agentic-tictactoe

Ensures all quality checks pass locally before committing changes. Use this skill to validate code quality, tests, and type checking before creating commits to catch issues early and avoid CI failures.

phase-implementation

13
from arun-gupta/agentic-tictactoe

Guides implementation of features following an established workflow pattern. Use when implementing any feature to ensure consistent process: read requirements, create todos, implement code, write tests, update documentation, commit and push.

implementation-plan-updates

13
from arun-gupta/agentic-tictactoe

Defines the pattern for updating project documentation when completing features. Use when marking features as complete to ensure consistent documentation of implementation status, test coverage, and deliverables.

commit-format

13
from arun-gupta/agentic-tictactoe

Ensures all git commits follow the Conventional Commits specification with consistent types and scopes. Use this skill when making any commit to maintain consistent commit message format, improve git history readability, and enable automatic changelog generation.

api-endpoint-implementation

13
from arun-gupta/agentic-tictactoe

Defines patterns for implementing FastAPI REST endpoints, including route definition, request/response models, error handling, and integration tests. Use when implementing any API endpoint to ensure consistency and best practices across endpoints.

jepsen-testing

16
from plurigrid/asi

Jepsen-style correctness testing for distributed systems under faults (partitions, crashes, clock skew) using concurrent operation histories and formal checkers (linearizability/serializability and Elle-style anomalies). Use when designing, implementing, or running Jepsen tests, or interpreting histories/violations.

Writing Hookify Rules

16
from plurigrid/asi

This skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.

webapp-testing

16
from plurigrid/asi

Toolkit for interacting with and testing local web applications using

topos-adhesive-rewriting

16
from plurigrid/asi

Adhesive categories for incremental query updating and pattern rewriting

testing-websocket-api-security

16
from plurigrid/asi

Tests WebSocket API implementations for security vulnerabilities including missing authentication on WebSocket upgrade, Cross-Site WebSocket Hijacking (CSWSH), injection attacks through WebSocket messages, insufficient input validation, denial-of-service via message flooding, and information leakage through WebSocket frames. The tester intercepts WebSocket handshakes and messages using Burp Suite, crafts malicious payloads, and tests for authorization bypass on WebSocket channels. Activates for requests involving WebSocket security testing, WS penetration testing, CSWSH attack, or real-time API security assessment.