liveBook · Manning

Test-driven development

As explained in The Coder Cafe

Test-driven development is a development approach in which tests guide implementation, typically by writing a failing test before the corresponding code.

Test-driven development (TDD) is a workflow in which tests guide implementation. Its central loop is Red-Green-Refactor: write a failing test, add just enough code to pass it, then improve the structure while preserving passing behavior. section 5.6

A practical TDD cycle proceeds as follows:

  • Red: define expected behavior and edge cases in a test, then confirm that it fails. section 5.6
  • Green: implement the smallest solution that makes the test pass. section 5.6
  • Refactor: improve the implementation after the tests are green, using the tests to detect regressions. section 5.6
  • Treat TDD as a tool rather than a mandatory quality gate; writing tests before code is not universally suitable when APIs, data, or external services remain unclear. section 5.0 section 5.7

Sorting an array

For an array-sorting function, begin with tests for unsorted, already sorted, one-element, and empty arrays. Implement sorting until those tests pass, then refine the code while keeping them green. section 5.6

Visualizes the Red-Green-Refactor cycle as a repeating implementation workflow. section 5.6

How The Coder Cafe covers it

How deep it goes
Defines the Red-Green-Refactor process, gives a sorting example, and weighs suitability without prescribing universal adoption.
Examples
Uses an array-sorting function with unsorted, sorted, one-element, and empty-array cases.
What it assumes
Assumes code and test-writing ability, while teaching behavior and edge-case definition through a concrete utility-function example.
What you can do after
Practice/perform it by cycling from failing behavior tests through minimal implementation to refactoring.
How it connects
Connects TDD with unit testing, refactoring, test behavior, code coverage, and property-based testing.

Also explained in

Compare how 23 books explain test-driven development →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Coder Cafe. The section links point to the parts of the book it draws on.