phase-test-tdd

Generate test files and coordinate test-driven development (TDD). Use when creating tests before implementation or during test phase.

⭐8stars🔀4forks📁View on GitHub🕐Updated Jan 3, 2026

When & Why to Use This Skill

This Claude skill streamlines the Test-Driven Development (TDD) workflow by automating the generation of test files and coordinating the Red-Green-Refactor cycle. It provides standardized testing patterns for Mojo and Python, ensuring high code reliability through unit, integration, and performance testing while enforcing strict coverage requirements and best practices.

Use Cases

  • TDD Workflow Management: Coordinate the full development cycle by writing failing tests first, then implementing minimal code to pass, followed by refactoring.
  • Automated Test Generation: Quickly create boilerplate test files for Mojo and Python projects, including unit, integration, and performance test structures.
  • Code Quality & Coverage Enforcement: Ensure software robustness by validating that new code meets minimum coverage thresholds (80%+) and covers critical edge cases.
  • Performance Benchmarking: Develop specialized performance tests to monitor and optimize SIMD and critical execution paths in high-performance applications.
namephase-test-tdd
description"Generate test files and coordinate test-driven development (TDD). Use when creating tests before implementation or during test phase."
mcp_fallbacknone
categoryphase
phaseTest
user-invocablefalse

Test-Driven Development Skill

Coordinate test-driven development by writing tests first, then implementing to make them pass.

When to Use

  • Creating tests before implementation (TDD workflow)
  • Starting test phase of 5-phase workflow
  • Writing unit, integration, or performance tests
  • Need test files following Mojo or Python patterns

Quick Reference

# TDD Cycle: Write test → Run (fail) → Implement → Run (pass) → Refactor

# Generate test file
cat > tests/test_component.mojo << 'EOF'
from testing import assert_equal

fn test_basic_behavior() raises:
    """Test basic functionality."""
    let result = function_under_test()
    assert_equal(result, expected_value)
EOF

# Run test (should fail initially)
mojo test tests/test_component.mojo

# Implement code to make test pass
# Re-run test (should pass)
mojo test tests/test_component.mojo

Workflow

  1. Write test first - Define expected behavior before implementation
  2. Run test (Red phase) - Test fails because code doesn't exist yet
  3. Implement code (Green phase) - Write minimal code to make test pass
  4. Refactor (Refactor phase) - Clean up while keeping tests passing
  5. Repeat - Add next test and repeat cycle

Test Types

Type Location Purpose
Unit tests/unit/ Test individual functions in isolation
Integration tests/integration/ Test component interactions
Performance tests/performance/ Benchmark SIMD and critical paths

Mojo Test Pattern

from testing import assert_equal, assert_true

fn test_add() raises:
    """Test addition operation."""
    # Arrange
    var a = 1
    var b = 2

    # Act
    var result = add(a, b)

    # Assert
    assert_equal(result, 3)

Python Test Pattern

import pytest

class TestComponent:
    """Test suite for component."""

    def test_basic(self):
        """Test basic functionality."""
        # Arrange
        data = prepare_data()

        # Act
        result = process(data)

        # Assert
        assert result == expected

Test Coverage Requirements

  • Minimum: 80% for new code
  • Critical paths: 100% coverage required
  • Edge cases: Must be tested (null, empty, boundary values)
  • Error handling: All error paths tested

Phase Dependencies

  • Precedes: Implementation phase (tests drive implementation)
  • Parallel with: Implementation and Package phases (all run after Plan)
  • Receives input from: Plan phase (specifications, acceptance criteria)
  • Produces for: Implementation phase (test contracts for code)

Output Location

  • Test files: /tests/<type>/<module>_test.mojo or .py
  • Test documentation: /notes/issues/<issue-number>/README.md
  • Coverage reports: coverage/ directory

Error Handling

Error Fix
Test import fails Check file path and module structure
Test timeout Optimize code or increase timeout
Flaky tests Add setup/teardown, check for randomness
Low coverage Add tests for uncovered branches

References

  • CLAUDE.md - "Key Development Principles" (TDD section)
  • CLAUDE.md - "Common Mistakes to Avoid" (test failure patterns)
  • notes/review/mojo-test-failure-learnings.md - Real test failure solutions

Key Principle: Red → Green → Refactor. Don't skip the red phase.