test-driven-development

Enforce a test-first workflow with the RED-GREEN-REFACTOR cycle.

247|22|Updated Dec 11, 2024
One-click install
npx skills add https://github.com/graniet/kheish --skill test-driven-development-graniet
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-driven-development
Source: https://github.com/graniet/kheish/tree/main/skills/software-development/test-driven-development
Command: npx skills add https://github.com/graniet/kheish --skill test-driven-development-graniet

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing production code before writing tests leads to untested edge cases, hidden bugs, post-change regressions, and wasted time debugging avoidable issues. This Skill eliminates that risk by enforcing a strict test-first workflow that ensures every piece of code is validated against expected behavior before it is merged.

Core Features & Use Cases

  • Strict RED-GREEN-REFACTOR Cycle: Enforces the mandatory order of writing a failing test first, writing minimal code to pass the test, then refactoring while keeping all tests green.
  • TDD Anti-Pattern Protection: Blocks common rationalizations for skipping TDD, such as writing tests after implementation or keeping unverified "reference" code.
  • Verification Checklists: Includes mandatory checkpoints to confirm each test was verified to fail before implementation, and all tests pass after changes.
  • Use Case: Use this Skill when implementing any new feature, bug fix, or refactor to ensure all code is fully tested, prevent regressions, and create living documentation of expected behavior via automated tests.

Quick Start

Use the test-driven-development skill to implement the new user login feature by first writing a failing test for each required behavior (such as successful login with valid credentials and error handling for invalid passwords) before writing any production code.

Frequently Asked Questions about test-driven-development

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

FAQPage Schema
How do I implement test-driven development to prevent bugs in new features?

Test-driven development prevents bugs by enforcing a test-first workflow where you write a failing test verifying intended behavior before any production code. You then write minimal code to pass the test and refactor while keeping all tests green.

What is the RED-GREEN-REFACTOR cycle in automated testing?

The RED-GREEN-REFACTOR cycle is the core test-driven development workflow requiring you to write a failing test first, implement minimal code to make it pass, then refactor the code while ensuring all automated tests remain green.

How do I use TDD for bug fixes and refactoring existing code?

TDD for bug fixes and refactoring requires writing a failing test that reproduces the bug or verifies the modified behavior before changing production code. This ensures all changes are validated against expected behavior and prevents regressions.

Does test-driven development work without automated testing infrastructure?

Test-driven development requires a codebase with automated testing infrastructure. You must be able to execute tests to verify they fail before implementation and confirm they pass after writing minimal code to satisfy the test conditions.

Why write tests before implementation instead of after the code is written?

Writing tests after implementation leads to untested edge cases, hidden bugs, and post-change regressions. A strict test-first workflow eliminates this risk by verifying every piece of code against expected behavior before it is merged.

What are common TDD anti-patterns to avoid during software development?

Common TDD anti-patterns include writing tests after implementation, keeping unverified reference code, and skipping the verification step that confirms a test actually fails before writing production code to pass it.