⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdrivenprogramming.html

📁 极限编程 Extream Programing
💻 HTML
字号:
<head><title>Test Driven Programming</title></head><body><h1><img src="logo.gif"> Test Driven Programming</h1><a href="ExtremeProgramming.html">ExtremeProgramming</a> champions the use of tests as a development tool.
Given an object, devise tests for all interesting methods even
before you program them.
This means that:
<UL><li> you are forced to define precisely what a method does
<li> you know where to begin writing a method
<li> you know when you are done writing a method
<li> you know the minimal scaffolding needed to run a method
</UL>This means that you will recognize dependencies among the objects early,
and work to minimize them.
You will have broken up your work, so you know at the beginning of
the day what you have to do, and you know when you are done.
<p>This style of programming gives you a continuity of
development that is inaccessible otherwise. 
You find mistakes early enough that the <a href="http://c2.com/cgi/wiki?DreadedDayOfDebugging">DreadedDayOfDebugging</a> becomes
a distant memory.
The effects of bugs in unrelated modules get detected when designing
test setup.
<p>You get to use debuggers as sharp, pointed, precise tools
rather than as shovels for digging for mistakes among mounds of
code.
When a test fails, you set a breakpoint and trace. Don't try to second
guess the computer. 
If the tests are fine enough, and the scaffolding small enough,
debug runs end very quickly.
You can think of this as ComputerAidedCodeInspection<a href="http://c2.com/cgi/wiki?edit=ComputerAidedCodeInspection">?</a>.
<p><p>It also means that you can refactor confidently, knowing that
your tests will protect you from mistakes.
In turn,
refactoring constantly keeps design warts from becoming cancers.
<p>When adding new functions, devise a new test. 
If the new feature suggests a change in the design, do it.
Your earlier tests let you do it without an <a href="http://c2.com/cgi/wiki?OhGod">OhGod</a> feeling lurking
in the background.
Then get the new test going.
<p>You can turn this style around to understand programs.
When trying to understand other peoples code, write tests for
it. Talk to them to find out what is their minimal scaffolding,
and how to compare results.
<p>I think of this programming style as a programmers version of 
the Dijkstra/Hoare/Gries (<a href="http://c2.com/cgi/wiki?EwDijkstra">EwDijkstra</a>,<a href="http://c2.com/cgi/wiki?CarHoare">CarHoare</a>) development technique. 
The scaffolding is the &quot;pre-condition&quot;, and the test is
the &quot;post-condition&quot;. 
Good tests look a lot like formulae: everything is reduced
to equality. 
Refactoring feels like rearranging formulae.
<p>I have used this style effectively in C++ programming
on the Choices project, where slow machines and miserable
environments discouraged rapid code turnaround, 
you had to compromise designs to achieve fast
compilation, debugging was hard, and so on.
Even so, it turned out that using well designed stubs of various type,
incremental programming *was* possible.
And the micro-testing meant that during kernel virtual memory
development, when printf could fail, and debuggers cease to operate,
and booting a machine (Encore Multimaxes) could take five minutes
by the clock, and so on, this style ended up being very effective
although it required a lot of care.
(In the end, we ended up creating the ultimate stub: the whole
operating system &quot;ported&quot; to the &quot;Unix Abstract Machine&quot;, using
mmap for VM, signals for interrupts, sigalarm for preemption,
and files as disks).
<p>The advocacy of this style in
<a href="ExtremeProgramming.html">ExtremeProgramming</a> finally cemented it for me.
As usual, <a href="http://c2.com/cgi/wiki?TomVanVleck">TomVanVleck</a> pages mention this style as well;
he calls it TestThenCode<a href="http://c2.com/cgi/wiki?edit=TestThenCode">?</a>.
Sometimes it seems that in programming (especially OSes), all roads lead back to Multics.
-- <a href="http://c2.com/cgi/wiki?AamodSane">AamodSane</a>
<p><em>Very nice, Aamod!  --<a href="RonJeffries.html">RonJeffries</a></em> <em>Please turn this into an article!</em>
<p><hr>
See: <a href="http://c2.com/cgi/wiki?CodeUnitTestFirst">CodeUnitTestFirst</a><hr><a href="http://c2.com/cgi/wiki?edit=TestDrivenProgramming">EditText</a> of this page (last edited December 21, 2000)<br><a href="http://c2.com/cgi/wiki?FindPage&value=TestDrivenProgramming">FindPage</a> by browsing or searching<p><font color=gray size=-1>This page mirrored in <a href="index.html">ExtremeProgrammingRoadmap</a> as of March 31, 2001</font></body>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -