Tdd methodoly expert

From thedaviddias/skill-check · View interactive version

Tdd methodoly expert is an AI agent skill from the GitHub repository thedaviddias/skill-check. Use when implementing features or fixing bugs with strict Test-Driven Development (TDD). Activate for coding tasks that require new functionality, refactoring, or comprehensive test coverage, especially when the user mentions TDD or Test Driven Development.

How to use this skill

Skill file

TDD Methodology Expert

Enforce and reinforce Test-Driven Development (TDD) methodology throughout the software development process. This skill provides comprehensive guidance, automated validation, and continuous reinforcement of the Red-Green-Refactor cycle.

When to Use This Skill

This skill automatically activates when:

Use this skill for:

Do NOT use this skill for:

Core TDD Methodology

Test-Driven Development follows a strict three-phase cycle that must be repeated for every increment of functionality:

🔴 Red Phase: Write a Failing Test

Always write the test before any production code.

  1. Write a test that expresses the desired behavior
  2. Run the test and verify it fails (for the right reason)
  3. Confirm the failure message indicates what's missing

Red Phase Principles:

Example Flow:

1. Write: test_should_calculate_total_with_tax()
2. Run: Test fails - "ShoppingCart has no attribute 'calculate_total'"
3. ✅ Ready for Green phase

🟢 Green Phase: Make the Test Pass

Write minimal code to make the failing test pass.

  1. Implement the simplest code that makes the test pass
  2. Run the test and verify it passes
  3. Run all tests to ensure nothing broke

Green Phase Principles:

Example Flow:

1. Implement: def calculate_total(self, tax_rate): ...
2. Run: Test passes ✅
3. Run all: All tests pass ✅
4. ✅ Ready for Refactor phase

🔵 Refactor Phase: Improve the Code

Clean up code while maintaining passing tests.

  1. Identify duplication, poor names, or structural issues
  2. Refactor incrementally, running tests after each change
  3. Verify all tests still pass
  4. Repeat until code is clean

Refactor Phase Principles:

Example Flow:

1. Identify: Duplicated tax calculation logic
2. Extract: Move to _calculate_tax() method
3. Run tests: All pass ✅
4. Improve: Better variable names
5. Run tests: All pass ✅
6. ✅ Commit and move to next feature

TDD Workflow Integration

Before Starting Any Code Task

Step 1: Understand the Requirement

Step 2: Plan the Test

During Implementation

Always follow this sequence:

  1. 🔴 Red: Write failing test → Run → Verify failure
  2. 🟢 Green: Write minimal code → Run → Verify pass
  3. 🔵 Refactor: Improve code → Run → Verify still passes
  4. Commit: Save working, tested, clean code
  5. Repeat: Next test for next behavior

Never skip phases or reverse the order.

Communicating TDD Progress

In every response involving code changes, explicitly state:

Example Communication:

🔴 RED PHASE: Writing a test for calculating order total with discounts.

Test: test_should_apply_percentage_discount_to_order_total()
Expected to fail because Order.apply_discount() doesn't exist yet.

[Test code here]

Running test... ❌ Fails as expected: "Order has no attribute 'apply_discount'"

🟢 GREEN PHASE: Implementing minimal code to pass the test...

[Implementation code here]

Running test... ✅ Passes!
Running all tests... ✅ All pass!

🔵 REFACTOR PHASE: Improving the discount calculation structure...

[Refactored code here]

Running all tests... ✅ All pass!
Ready to commit this increment.

Bundled Tools and Resources

Scripts

check_tdd_compliance.py

Analyzes code to detect TDD compliance issues and code smells that indicate test-after development.

Usage:

python scripts/check_tdd_compliance.py <path-to-code>

What it checks:

When to use:

validate_tests.py

Validates that tests exist, are properly structured, and follow TDD patterns.

Usage:

python scripts/validate_tests.py <path-to-tests>

What it checks:

When to use:

setup_hooks.sh

Installs git hooks and Claude Code hooks to enforce TDD methodology automatically.

Usage:

bash scripts/setup_hooks.sh <project-directory>

What it installs:

When to use:

References

Load these references when deeper understanding is needed:

tdd-principles.md

Comprehensive guide to TDD methodology including:

When to reference: When explaining TDD concepts or resolving questions about methodology.

code-smells.md

Catalog of code smells that indicate test-after development:

When to reference: When analyzing code quality or identifying non-TDD patterns.

Grep patterns for searching:

testing-patterns.md

Language-agnostic testing patterns and best practices:

When to reference: When writing tests or improving test structure.

Assets

Hook Templates

Located in assets/hook-templates/:

These templates are used by setup_hooks.sh and can be customized for specific project needs.

Further reference

See references/tdd-reference.md for prompt-based validation and setup, TDD enforcement rules, common scenarios, workflow integration, troubleshooting, and summary.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.