The Three Rules of TDD

Table of Contents

Robert C. Martin (“Uncle Bob”) provides a concise set of rules for practicing TDD.

  1. Write production code only to pass a failing unit test.

  2. Write no more of a unit test than sufficient to fail (compilation failures are failures).

  3. Write no more production code than necessary to pass the one failing unit test.

Rule #1 says to write tests first—understand and specify, in the form of a unit test example, behavior you must build into the system.

Rule #2 says to proceed as incrementally as possible—after each line you write, get feedback (via compilation or test run) if you can before moving on. When test-driving a RetweetCollection class, we stop as soon as we write this much of a first test:

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: 程序人生