tdd-bug-fix

Fix bugs using red-green-refactor by writing a failing regression test before applying the fix.

696|66|Updated Oct 29, 2025
Ready to run
npx skills add https://github.com/rshankras/claude-code-ios-skills --skill tdd-bug-fix
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: tdd-bug-fix
Source: https://github.com/rshankras/claude-code-ios-skills/tree/main/skills/testing/tdd-bug-fix
Command: npx skills add https://github.com/rshankras/claude-code-ios-skills --skill tdd-bug-fix

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bug fixes applied without tests often fail to address the root cause or silently regress later. This Skill enforces a reproduce-first workflow so every fix is verified by a failing test that becomes a permanent regression guard.

Core Features & Use Cases

  • Red-Green-Refactor Workflow: Reproduce the bug as a failing Swift Testing test, apply a minimal fix, then verify no regressions across the full test suite.
  • Bug Test Templates: Ready-made templates for logic bugs, async bugs, state bugs, edge cases, and UI state bugs using Swift Testing (@Test, #expect).
  • Verification Checklist: Confirms the test fails before the fix, passes after, and that all existing tests still pass.
  • Use Case: A user reports that a 50% discount on $100 returns $0.50 instead of $50. Write a failing test reproducing the miscalculation, fix the double division in the source, and keep the test as a permanent regression guard.

Quick Start

Ask the AI to fix a reported bug using TDD by first writing a failing test that reproduces it, then making the test pass.

Frequently Asked Questions about tdd-bug-fix

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a bug using TDD in Swift?▼

Write a failing test that reproduces the bug first (RED), then apply a minimal fix to make it pass (GREEN), and optionally refactor with all tests green. Use Swift Testing with @Test and #expect, and run tests via xcodebuild.

How to write a failing test that reproduces a bug?▼

Identify the triggering input and expected behavior, then assert the correct output in a test targeting the buggy function. Run the test and confirm it fails; if it passes, the bug is not reproduced and assertions need to be more specific.

Does this TDD approach work with Swift Testing and XCTest?▼

The templates use Swift Testing (@Suite, @Test, #expect) and run with xcodebuild's -only-testing flag. The same red-green-refactor process applies to XCTest-based suites as well.

Why does my bug reproduction test pass before the fix?▼

A passing test means the bug was not actually reproduced. Make assertions more specific, match the exact triggering input, and verify you are testing the code path where the bug lives.

When should I not use TDD for a bug fix?▼

Avoid it when the buggy behavior is not yet understood or characterized; capture existing behavior with characterization tests first. Also avoid broad fixes that break other tests—revert and apply a smaller targeted change instead.