liveBook · Manning

Test-driven development

As explained in Vibe Engineering

A development practice in which automated tests are written before the production code that satisfies them.

Test-driven development (TDD) defines expected behavior in automated tests before writing the code that satisfies them. In AI-assisted development, the engineer can write the tests while a model implements the function. The ordering matters: defining correctness first encourages active consideration of failure modes before generated code influences judgment. section 1.4

import pytest
# Assume is_valid_isbn13 is the function to be generated
def test_valid_isbn_with_hyphens():
    assert is_valid_isbn13("978-0-306-40615-7") is True
def test_valid_isbn_without_hyphens():
    assert is_valid_isbn13("9780306406157") is True
def test_invalid_checksum():
    assert is_valid_isbn13("978-0-306-40615-0") is False
def test_invalid_length():
    assert is_valid_isbn13("978-0-306-40615") is False
def test_contains_non_numeric_characters():
    assert is_valid_isbn13("978-0-306-40615-X") is False

These pytest cases define expected behavior for an ISBN-13 validator before implementation, including valid formats, an invalid checksum, incorrect length, and nonnumeric characters. section 1.4

A passing suite verifies only the checks it contains. For a feature, extend the contract beyond function tests to cover API schemas, invariants, error semantics, and performance gates. Security also needs explicit requirements and a separate verification gate; happy-path tests alone can miss a vulnerable implementation. section 1.4 section 1.5

At feature scale, the familiar Red → Green → Refactor rhythm becomes Specify → Implement → Verify. A human-authored executable specification guides implementation and verification; engineers still need to judge whether it captures the intended behavior before merging. section 1.5 section 1.8

How Vibe Engineering covers it

How deep it goes
Explains test-first ordering and its rationale, then extends the rhythm to feature contracts and verification gates.
Examples
Uses an ISBN-13 validator test suite covering valid formats, invalid checksums, length, and nonnumeric characters.
What you can do after
Apply test-first verification to AI-generated functions and evaluate whether broader feature contracts cover critical behavior.
How it connects
Connects TDD to spec-driven development, executable specifications, security testing, and automation bias.

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 Vibe Engineering. The section links point to the parts of the book it draws on.