test-driven-development

Drives development with tests. Use when implementing any logic, fixing any bug, or changing any behavior. Use when you need to prove that code works, when a bug report arrives, or when you're about to modify existing functionality.

Install

Hot:61

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=addyosmani-skills-test-driven-development&locale=en&source=copy

Test-Driven Development (TDD)

Skill Overview


Test-driven development is a development approach in which tests are written before code. It ensures code quality through the red-green-refactor cycle and is suitable for implementing new features, fixing bugs, and refactoring code.

Applicable Scenarios


  • When implementing new logic or features - Write tests before writing business code to clarify the expected behavior and prevent the implementation from deviating from requirements.

  • When fixing bugs - First reproduce the bug with a test to prove that the problem exists, then implement the fix and ensure that it does not regress.

  • When refactoring existing code - Establish a test safety net before modifying the code structure to ensure that the refactoring does not break existing functionality.
  • Core Features


  • The TDD Red-Green-Refactor Cycle - Guides developers through a three-step cycle: “write a failing test → write the minimal implementation → refactor and optimize.” Each step has clear verification criteria.

  • The Prove-It Fix Pattern - Requires writing a reproduction test for every bug to ensure that the fix truly resolves the problem and prevents regression.

  • The Testing Pyramid Methodology - Allocates testing effort in a ratio of 80% unit tests, 15% integration tests, and 5% E2E tests to maximize testing efficiency and confidence.
  • Frequently Asked Questions

    What is the TDD red-green-refactor cycle?


    Red-green-refactor is the core workflow of TDD: In the red phase, first write a failing test to prove that the functionality is missing; in the green phase, write the simplest code necessary to make the test pass; in the refactor phase, improve the code structure under the protection of the tests. This cycle is repeated continuously to ensure that every line of code is covered by tests.

    Why should you write a test before fixing a bug?


    Directly modifying the code may only make the problem appear to be fixed, without proving that the fix is effective or that it will not introduce new issues. Writing a failing test first clearly reproduces the bug. When the test passes after the fix, it proves that the fix works, and any future regression will be immediately caught by the test. This is the “prove it” pattern.

    What is the difference between unit tests and integration tests?


    Unit tests target the pure logic of a single function or class and do not depend on external resources such as databases, networks, or file systems. They run quickly, typically within milliseconds. Integration tests verify that multiple components work together or that operations crossing system boundaries—such as API calls and database reads and writes—function correctly. They are slower but cover real interactions. According to the testing pyramid, most tests should be fast unit tests.