From 5feebda1f4602a56ae40faea86d3c2759b0a1a6e Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 11 Sep 2009 16:21:35 -0400 Subject: [PATCH] rephrase intro section to better distinguish TDD and unit testing --- unit-testing.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit-testing.html b/unit-testing.html index 3e24069..8284cd1 100755 --- a/unit-testing.html +++ b/unit-testing.html @@ -32,8 +32,8 @@ body{counter-reset:h1 9}

Let’s start mapping out what a roman.py module should do. It will have two main functions, to_roman() and from_roman(). The to_roman() function should take an integer from 1 to 3999 and return the Roman numeral representation as a string…

Stop right there. Now let’s do something a little unexpected: write a test case that checks whether the to_roman() function does what you want it to. You read that right: you’re going to write code that tests code that you haven’t written yet. -

This is called unit testing. The set of two conversion functions — to_roman(), and later from_roman() — can be written and tested as a unit, separate from any larger program that imports them. Python has a framework for unit testing, the appropriately-named unittest module. -

Unit testing is an important part of an overall testing-centric development strategy. If you write unit tests, it is important to write them early (preferably before writing the code that they test), and to keep them updated as code and requirements change. Unit testing is not a replacement for higher-level functional or system testing, but it is important in all phases of development: +

This is called test-driven development, or TDD. The set of two conversion functions — to_roman(), and later from_roman() — can be written and tested as a unit, separate from any larger program that imports them. Python has a framework for unit testing, the appropriately-named unittest module. +

Unit testing is an important part of an overall testing-centric development strategy. If you write unit tests, it is important to write them early and to keep them updated as code and requirements change. Many people advocate writing tests before they write the code that the test tests, and that’s the style I’m going to demonstrate in this chapter. But unit tests are beneficial no matter when you write them.