software-engineering testing

Definition

Test-Driven Development (TDD)

A software development process where you write the test before you write the code. It relies on a very short development cycle:

  1. Add a test for a small piece of functionality.
  2. Run the test and see it fail (Red).
  3. Write just enough code to make the test pass (Green).
  4. Refactor the code to improve design while keeping tests green.

Pros

  • Design Feedback: Writing the test first forces you to design the API from the client’s perspective (usability).
  • Rapid Feedback: Bugs are caught instantly.
  • Testability: Code is testable by definition (since it was written to satisfy a test).
  • Confidence: Enables aggressive refactoring later.
  • Velocity: Developers can choose their speed by taking smaller or larger steps.

Cycle

  1. Red: Write a failing test (compilation error or assertion failure).
  2. Green: Make it pass as simply as possible (even if it means hardcoding).
  3. Refactor: Clean up duplication and improve structure.