liveBook · Manning

Test-driven development

As explained in Software Testing with Generative AI

Test-driven development is a software development practice in which failing checks are created before production code, code is added to make them pass, and the code is then refactored while checks remain passing.

Test-driven development (TDD) builds quality through a repeated red/green/refactor loop: create a failing unit check, add just enough production code to pass it, then refactor while all checks remain green. section 4.3

Follow the loop in this order:

  • Write a focused failing check for the behavior you want. section 4.3
  • Implement only enough production code to make the check pass, fixing regressions revealed by the check suite. section 4.3
  • Refactor the implementation without allowing checks to become red, then begin the next loop. section 4.3

Timesheet manager

A timesheet feature can begin with checks for tracking time against a project in half-hour units, requiring both a project and duration, and restricting visibility to the current user. Production code is added incrementally to satisfy those checks. section 4.4

Figure 4.1 The red/green/refactor TDD cycle

Use the red/green/refactor figure as a compact visual map of the repeating TDD cycle. section 4.3

Unit-checking tools rapidly verify explicit, narrowly defined assertions; they do not reveal everything about a system. Human judgment remains necessary to assess simultaneous events, user needs, business goals, design, and risks. LLM tools can accelerate check and code creation, but developers must lead the analytical and design work and verify generated output. section 4.1 section 4.3

How Software Testing with Generative AI covers it

How deep it goes
Explains the red/green/refactor procedure and its rationale, but stops short of detailed implementation code.
Examples
Demonstrates a timesheet manager feature involving projects, half-hour units, required inputs, and user-specific visibility.
What it assumes
Assumes familiarity with production code and unit-checking tools while teaching the TDD loop and human-tool distinction.
What you can do after
Apply it to build incrementally testable features while preserving passing checks during refactoring.
How it connects
Connects TDD with unit testing, automated checking, code design, product quality, human testing, and LLM assistance.

Also explained in

Compare how 15 books explain test-driven development →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.