mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
further clarifications
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ body{counter-reset:h1 9}
|
||||
<p>Let’s start mapping out what a <code>roman.py</code> module should do. It will have two main functions, <code>to_roman()</code> and <code>from_roman()</code>. The <code>to_roman()</code> function should take an integer from <code>1</code> to <code>3999</code> and return the Roman numeral representation as a string…
|
||||
<p>Stop right there. Now let’s do something a little unexpected: write a test case that checks whether the <code>to_roman()</code> 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.
|
||||
<p>This is called <i>test-driven development</i>, or <abbr>TDD</abbr>. The set of two conversion functions — <code>to_roman()</code>, and later <code>from_roman()</code> — 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 <code>unittest</code> module.
|
||||
<p>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.
|
||||
<p>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 they’re testing, and that’s the style I’m going to demonstrate in this chapter. But unit tests are beneficial no matter when you write them.
|
||||
<ul>
|
||||
<li>Before writing code, it forces you to detail your requirements in a useful fashion.
|
||||
<li>While writing code, it keeps you from over-coding. When all the test cases pass, the function is complete.
|
||||
|
||||
Reference in New Issue
Block a user