liveBook · Manning

Test-driven development

As explained in Spec-Driven Development

Test-driven development is a software development practice in which an automated test is written before the implementation that makes it pass.

Test-driven development (TDD) uses unit tests to drive implementation and design from the inside out, while keeping implementation within architectural boundaries. section 4.2.3

Distinguish TDD from outside-in acceptance testing: acceptance tests verify behavior against acceptance criteria before implementation begins; unit tests then drive design within architectural boundaries. section 4.2.3

Listing 1.3 Test to verify session invalidation after a password reset
test "password reset invalidates all existing sessions for the user"
    # Arrange
    user = create_user_with_password("old-password")
    session_1 = login(user, device="laptop")
    session_2 = login(user, device="phone")
    session_3 = login(user, device="tablet")
    reset_token = request_password_reset(user.email)
    # Act
    complete_password_reset(reset_token, new_password="new-password")
    # Assert
    assert session_store.active_sessions_for(user.id) == []

A password-reset test arranges three active sessions, completes a reset, and asserts that no sessions remain. section 1.2

How Spec-Driven Development covers it

How deep it goes
Distinguishes inside-out unit-test-driven design from outside-in acceptance verification without spelling out a full TDD cycle.
Examples
Uses password-reset session invalidation as a test example and a URL-shortener task list as a workflow scenario.
What you can do after
Apply TDD by letting unit tests drive implementation design while respecting architectural boundaries.
How it connects
Connects unit tests and architectural boundaries with acceptance tests and acceptance criteria.

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