    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Vorsprung Durch Testing</title>
        <link>https://members.accu.org/index.php/articles/293</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Design of applications and programs + Overload Journal #69 - Oct 2005</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c67/">Design</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c143/">69</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c67-143/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c67+143/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Vorsprung Durch Testing</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 October 2005 05:00:00 +01:00 or Sun, 02 October 2005 05:00:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>At times it might seem as if the T in TDD stands for Trendy, but
there is more to Test-Driven Development than just a statement of
fashion. There is also more to it than just testing.</p>
<p>It is possible to identify a subset of three motivating
practices in TDD that characterise a fairly conventional and
uncontentious form of unit testing [<a href=
"#Henney1">Henney1</a>]: <span class="emphasis"><em>programmer
testing responsibility</em></span>, <span class=
"emphasis"><em>automated tests</em></span> and <span class=
"emphasis"><em>example-based test cases</em></span>. These form a
unit-testing base that can be employed in the context of both
static and agile development macro processes, and were motivated
and demonstrated previously on the humble but surprisingly rich
example of a sorting function in C [<a href=
"#Henney2">Henney2</a>]. Thus, programmers are responsible for unit
testing their work, with system-level testing a separate and
complementary role and activity; tests should be executed
automatically - execution of code by code - rather than manually;
tests are black-box tests expressed as specific examples of typical
or edge cases of using the unit under test.</p>
<p>The next step is to recognise that effective testing can be more
than just bug hunting. In TDD unit testing helps to support and
drive design, and vice-versa. Three more practices can be
identified that build on the core unit-testing foundation to
provide us with a micro-process component that also supports
design: active test writing, sufficient design and refactoring.
These design-focused practices expand the role of the basic
unit-testing practices: examples drive the scope of design
[<a href="#Marick">Marick</a>], programmer responsibility extends
to the suitability and quality of code over time - not just at a
single point in time - and automation underpins the practical
execution of this approach.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e44" id="d0e44"></a>Active Test
Writing</h2>
</div>
<p>Black-box testing by example is not just limited to exploring
the correctness of an implementation against an interface contract:
it is also useful for framing and presenting it, and for
formulating and exploring the contract itself. In other words,
design.</p>
<p>Passive testing is essentially the process whereby the feedback
of tests is limited to defect detection. Tests are typically
written some time after the code they test, where they play what is
essentially a destructive role: they cannot confirm total
correctness, only the presence of incorrectness. Although such an
approach to testing has obvious value, it can encourage an approach
to both design and testing that is overly formal and sequential.
The opportunity to learn about what is being designed, and how to
design it better as a whole, is missed [<a href=
"#Henney3">Henney3</a>]. Defects lead to localised fixes, but the
test-writing process does not influence the key decisions in a
design, which in effect is considered frozen. The feedback loop is
too long, so there is less motivation to change things because of
the feeling of &quot;what's done is done&quot;. The code has effectively gone
into conventional maintenance mode early, even though initial
development may be ongoing.</p>
<p>Active test writing adopts a more balanced perspective, using
the act of test writing as a creative exercise to balance the more
destructive intentions of test execution. Tests represent a first
point of use of an interface, and the ease or difficulty of writing
test cases gives instant feedback on the qualities of the interface
and the implementation behind it.</p>
<p>High coupling manifests itself in tests that are difficult or -
in simple unit-testing terms - impossible to write. For example, an
object that depends on data that could be passed in, but has
instead ended up being coupled to a configuration file or registry,
a database connection or some global variable (whether expressed
obviously as such a variable or disguised as a singleton
object).</p>
<p>Low cohesion manifests itself in supernumerary test cases that
test quite unrelated features, suggesting that inside a given unit
there are smaller units struggling to get out. For example, the
standard C <tt class="function">realloc</tt> function expresses
three quite distinct behaviours: <tt class="function">malloc</tt>,
<tt class="function">free</tt> and, <tt class="function">err</tt>,
<tt class="function">realloc</tt> [<a href="#Henney4">Henney4</a>].
The standard <tt class="literal">java.util</tt> package contains
miscellaneous unrelated facilities - collections, event-handling
models, date and time handling, internationalisation features...
and further miscellaneous miscellanea. It also stands as a caution
to anyone who might consider <tt class="literal">util</tt>,
<tt class="literal">utils</tt>, <tt class="literal">utilities</tt>,
<tt class="literal">utility</tt>, etc, to be a clear and cohesive
name for a header, a package, a library, etc.</p>
<p>In terms of organising the <span class=
"emphasis"><em>active</em></span> part of <span class=
"emphasis"><em>active test writing</em></span>, there are many
options. The bottom line is that writing of test code is carried
out in close proximity - both space and time - to writing of
production code. The writing of test cases and corresponding
implementation can be interleaved, with one following or preceding
the other closely, or stepped a little further apart. Being able to
write a test case first is a useful and helpful discipline, but
only dogma would suggest that its exclusive use is an absolute
requirement and a necessary prerequisite of TDD. However, although
writing test cases much later than the target code can work, both
the quality of the feedback and the motivation to do so is
weaker.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e101" id="d0e101"></a>Sufficient
Design</h2>
</div>
<p>This continuous and reflective view of design at the code face
may raise another question in some minds about the whole nature of
developing iteratively and incrementally: why not just &quot;do the
right thing first time&quot;? Perhaps surprisingly, I have heard this
question posed as a serious criticism, but the question itself
raises more questions about the meaning of the question and the
questioner's assumptions than it does about agile development
techniques at any level. It assumes that the &quot;right thing&quot; is in
some way knowable &quot;first time&quot; and constant thereafter. However,
the &quot;right thing&quot; is dependent on time and is anything but
constant, so both &quot;right thing&quot; and &quot;first time&quot; lose their simple
interpretations. The learning nature of software development pretty
much guarantees that the knowledge of what it is to be built and
how it can be built are moving targets. While they may not
necessarily be wild and erratic, their variability stands to
undermine any approach that is based on constancy and precognition.
The difference between a process with no variables and one with
some is the difference between defined and empirical processes.
Treating an empirical process as a defined process is a problem
waiting to happen [<a href="#Schwaber">Schwaber</a>].</p>
<p>Yet there can still be a lingering sense that sorting everything
out up front is both reasonable and do-able, leading one way or
another to a <span class="emphasis"><em>big up-front
design</em></span> (BUFD) phase (see sidebar, <span class=
"emphasis"><em>&quot;Big&quot;, as in &quot;a Lot of&quot;, not just &quot;a Bit
of&quot;</em></span>). This inevitably leads to overdesign. Design based
on assumptions that turn out to be incorrect needs to be reworked,
often quite late. Design that tries to tackle uncertainty by being
less specific becomes lost in technical detail focused on
generality rather than on the actual problems that need to be
addressed. At the opposite end of the spectrum is no <span class=
"emphasis"><em>up-front design</em></span> (NUFD), which represents
a failure to exercise, in a timely manner, even the most basic
knowledge about what is to be developed. An approach based on a
view that accepts change but seeks stability is likely to be a more
reasoned one, albeit a little rougher in its detail up front, where
roughness implies sketched rather than shoddy. An approach based on
what I have referred to in recent years as <span class=
"emphasis"><em>rough up-front design</em></span> (RUFD) can steer
this middle path. Establish a stable baseline architecture that
expresses a common vision and a sketch of what is to be worked on,
without wasting time on details that are better expressed and
handled in code or that are best left until more concrete knowledge
is available. Note that stable is not the same as static, so the
architecture is open to change rather than being frozen. This
approach can also be dubbed <span class="emphasis"><em>sufficient
up-front design</em></span> (SUFD).</p>
<div class="sidebar">
<p class="title c3">&quot;Big&quot;, as in &quot;a Lot of&quot;, not just &quot;a Bit
of&quot;</p>
<p>It is worth clarifying what BUFD (or BDUF, as it is also known)
entails, because this appears to be an occasional source of
confusion. For example, misunderstanding its meaning can lead to
proclamations such as the following [<a href=
"#Spolsky">Spolsky</a>]:</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>I can't tell you how strongly I believe in Big Design Up Front,
which the proponents of Extreme Programming consider anathema. I
have consistently saved time and made better products by using BDUF
and I'm proud to use it, no matter what the XP fanatics claim.
They're just wrong on this point and I can't be any clearer than
that. And, to demonstrate the point, Joel Spolsky makes available
for download a so-called functional spec of a commercial product,
codenamed Aardvark. However, the deeds do not support the words.
The document may have been written up front, but hunt all you like
for big design because you won't find it. Strong belief and pride
appear to have clouded correct use of accepted terminology.</p>
</blockquote>
</div>
<p>The accepted archetype of BUFD arises from the strict waterfall
approach of defining development as a precisely phased pipeline of
activities, so that requirements analysis strictly precedes design
activity, which strictly precedes coding, which strictly precedes
testing. In a bid to reduce risk from unknowns later in the
lifecycle, a BUFD approach doesn't just do a bit of design up
front, it does a lot. Hence the use of the term <span class=
"emphasis"><em>big</em></span> rather than <span class=
"emphasis"><em>a bit of</em></span> or <span class=
"emphasis"><em>some</em></span>. The BUFD path is paved with good
intentions - even if somewhat suspect - but the idea is that the
design goes into a lot of detail, specifying internal structure to
the nth degree - from packages and classes right down to private
methods and private data. In essence, a blueprint that supports a
plan-driven model of development.</p>
<p>However, at the beginning of the Aardvark spec is the following
note:</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>This specification is simply a starting point for the design of
Aardvark 1.0, not a final blueprint. As we start to build the
product, we'll discover a lot of things that won't work exactly as
planned. We'll invent new features, we'll change things, we'll
refine the wording, etc. We'll try to keep the spec up to date as
things change. By no means should you consider this spec to be some
kind of holy, cast-in-stone law.</p>
</blockquote>
</div>
<p>So, of all the things this spec might be, a big, up-front design
document is not one of them. It makes this quite clear to the
reader by describing itself as &quot;a starting point for the design&quot;
not &quot;the design&quot;. Reading further into the spec uncovers frequent
use of words such as &quot;maybe&quot;, &quot;probably&quot; and &quot;possibly&quot; to describe
certain technical decisions. And then there is the length of the
document itself: twenty pages. When you strip away the extraneous
details, such as the front cover, preamble and the neo-Hungarian
coding conventions, you are left with a shorter document that
outlines some of the core requirements, proposes a user interaction
model and sketches a few features of the architecture. The document
is also not heavy on text and is fairly generous with its use of
spacing. Whichever way you look at it, this is not big design.
Which all comes as a welcome relief, but does rather undermine the
claim of its author.</p>
<p>Advocates of genuine BUFD would regard the Aardvark spec as
incomplete and insubstantial, lacking detailed specifications of
code structure or the look and feel of the application. They would
tar it with the same brush that the article uses to daub XP. I
believe that the contrast the article is trying to make is to
compare no up-front design with some up-front design, not with big
up-front design. Joel Spolsky is actually advocating a design
approach based on sufficiency, exploration and incrementalism. So
although he may not be on the same page as XP advocates, he is many
pages short of being a fully paid-up BUFD practitioner.</p>
</div>
<p>Sufficient design in TDD manifests itself in test-bounded design
increments, where tests describe the scope of what is being worked
on at any point in time. This moderates creeping featurism, cuts
extraneous code and encourages incremental and measured progress.
Active testing supports the goal of sufficient design by keeping
the role of functions, classes and packages clearly defined. Tests
bound the functional behaviour of these units, keeping them
'honest' with respect to their current role in the enclosing
system.</p>
<p>Driving the design from the baseline architecture through tests
leads to more cleanly separated units with a close dependency
horizon (a dependency occurs where one unit, e.g. class or header,
depends on another unit for its definition, e.g. inheritance or
inclusion, and the dependency horizon for a given unit is where its
dependencies end, i.e. where its immediate dependencies, and their
immediate dependencies in turn, and so on, have no further
dependencies). Of course, there needs to be some coupling at
certain levels otherwise, by definition, no coupling results in no
system.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e161" id=
"d0e161"></a>Refactoring</h2>
</div>
<p>Mrs Beeton's Victorian domestic advice [<a href=
"#Beeton">Beeton</a>] is surprisingly relevant to modern code:</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>A dirty kitchen is a disgrace to all concerned. Good cookery
cannot exist without absolute cleanliness. It takes no longer to
keep a kitchen clean and orderly than untidy and dirty, for the
time that is spent in keeping it in good order is saved when
culinary operations are going on and everything is clean and in its
place. Personal cleanliness is most necessary, particularly with
regard to the hands.</p>
</blockquote>
</div>
<p>This is the very motivation and essence of refactoring.
Refactoring preserves the functional behaviour of a piece of code
while changing - and, one hopes, improving - its developmental
qualities. Refactoring is a stable and local change, typically
motivated by a required change in functionality. Operational
behaviour, such as performance or memory usage, may change, but
improvement of operational qualities rather than developmental
qualities is the focus of the similar but distinct activity of
optimisation.</p>
<p>Changes to functionality may follow the line of the existing
code easily, requiring no more than a consistent extension or
in-place modification of the code. At other times a change in
functionality may also suggest a change in implementation of an
interface. An existing implementation may be OK in other respects,
but may support the functionality change poorly, requiring undue
effort to implement it. For example, the need to perform general
date arithmetic on an existing date representation that favours
presentation over calculation, such as <tt class=
"literal">YYYY-MM-DD</tt>, suggests that a change in representation
may be appropriate before extending the functionality [<a href=
"#Henney5">Henney5</a>]. Alternatively, the quality of an existing
piece of code may generally be poor, caught in a tangle of
spaghetti flow or spaghetti inheritance. For example, a self-aware
class hierarchy, where the root of the class hierarchy depends on
other classes in the hierarchy, can be a troublesome knot in the
dependency graph of a program, rather than an exemplary pattern to
be followed elsewhere.</p>
<p>Refactoring acknowledges that we can lay down code in confidence
but still learn better ways of achieving the same end. Indeed, it
is more than this: the learning is not simply passive; it is put
into practice and draws from practice. Of course, there is a risk
that making such a change is not necessarily an improvement: any
modification runs the risk of introducing a bug. Therefore,
practise with a safety net: refactoring should be undertaken with a
clear head, with another pair of eyes, with tools, with tests, or
with any suitable combination of these. In the context of a
test-driven approach, test cases offer a regression test suite that
act as a baseline for both refactoring and optimisation.</p>
<p>Given that the inevitability of change is one of the few
constants in software development, this active acknowledgement and
positive support of change through tests is reassuring. Refactoring
is the other side of the design coin from what we might consider to
be <span class="emphasis"><em>prefactoring</em></span>. Refactoring
adjusts the design vision and detail after the fact to balance the
formulation beforehand.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e189" id="d0e189"></a>Test Match
Report</h2>
</div>
<p>Test-Driven Development is a bar-raising, learning process.
Removing the tests leaves the safety net at ground level and
knowledge localised, isolated and transitory. A TDD approach offers
more than just a pile of tests: it offers specification as well as
confirmation. Both of these reasons are sufficient to justify
writing tests that sometimes apparently test the trivial. And
specifying even the trivial to be sure that it always works means
that regression testing comes for free as part of the deal.</p>
<p>Another consequence of TDD is the resolution of an imbalance in
the traditional view of testing. Testing is often characterised as
a destructive activity, and one that is predominantly quantitative
in its feedback. TDD makes testing a constructive activity, with
qualitative feedback on design, not just defect reports.</p>
<p>TDD is not a total process: you need other complementary drivers
to move development forward. For example, an incremental macro
process where each increment is scoped with respect to functional
or technical objectives provides a good backdrop to the code-facing
emphasis of TDD. Likewise, practices such as reviewing, joint
design meetings and continuous integration support and are
supported by TDD. It is also important to distinguish TDD from XP:
although historically it emerged from XP, TDD is neither a synonym
nor a metonym for XP. Implementing XP necessitates employing TDD,
but the converse is not true. TDD fits with many different
macro-process models. There are many more programmers practising
TDD in other processes than are using it in a strict XP
environment.</p>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e198" id="d0e198"></a>References</h2>
</div>
<div class="bibliomixed"><a name="Henney1" id="Henney1"></a>
<p class="bibliomixed">[Henney1] Kevlin Henney, &quot;Driven to Tests&quot;,
<span class="citetitle"><i class="citetitle">Application
Development Advisor</i></span>, May 2005, available from
<span class="bibliomisc"><a href="http://www.curbralan.com" target=
"_top">http://www.curbralan.com</a></span>.</p>
</div>
<div class="bibliomixed"><a name="Henney2" id="Henney2"></a>
<p class="bibliomixed">[Henney2] Kevlin Henney, &quot;C-side Re-sort&quot;,
<span class="citetitle"><i class="citetitle">Overload
68</i></span>, August 2005.</p>
</div>
<div class="bibliomixed"><a name="Marick" id="Marick"></a>
<p class="bibliomixed">[Marick] Brian Marick, <span class=
"citetitle"><i class="citetitle">Driving Software Projects with
Examples</i></span>, <span class="bibliomisc"><a href=
"http://www.exampler.com" target=
"_top">http://www.exampler.com</a></span>.</p>
</div>
<div class="bibliomixed"><a name="Henney3" id="Henney3"></a>
<p class="bibliomixed">[Henney3] Kevlin Henney, &quot;Learning Curve&quot;,
<span class="citetitle"><i class="citetitle">Application
Development Advisor</i></span>, March 2005, available from
<span class="bibliomisc"><a href="http://www.curbralan.com" target=
"_top">http://www.curbralan.com</a></span>.</p>
</div>
<div class="bibliomixed"><a name="Henney4" id="Henney4"></a>
<p class="bibliomixed">[Henney4] Kevlin Henney, &quot;No Memory for
Contracts&quot;, <span class="citetitle"><i class=
"citetitle">Application Development Advisor</i></span>, September
2004, available from <span class="bibliomisc"><a href=
"http://www.curbralan.com" target=
"_top">http://www.curbralan.com</a></span>.</p>
</div>
<div class="bibliomixed"><a name="Schwaber" id="Schwaber"></a>
<p class="bibliomixed">[Schwaber] Ken Schwaber and Mike Beedle,
<span class="citetitle"><i class="citetitle">Agile Development with
Scrum</i></span>, Prentice Hall, 2002.</p>
</div>
<div class="bibliomixed"><a name="Beeton" id="Beeton"></a>
<p class="bibliomixed">[Beeton] Isabella Beeton, <span class=
"citetitle"><i class="citetitle">Mrs Beeton's Every-Day Cookery and
Housekeeping Book</i></span>, Ward, Lock &amp; Co Ltd, 1872.</p>
</div>
<div class="bibliomixed"><a name="Henney5" id="Henney5"></a>
<p class="bibliomixed">[Henney5] Kevlin Henney, &quot;The Taxation of
Representation&quot;, <span class="citetitle"><i class=
"citetitle">artima.com</i></span>, July 2003, <span class=
"bibliomisc"><a href=
"http://www.artima.com/weblogs/viewpost.jsp?thread=8791" target=
"_top">http://www.artima.com/weblogs/viewpost.jsp?thread=8791</a></span>.</p>
</div>
<div class="bibliomixed"><a name="Spolsky" id="Spolsky"></a>
<p class="bibliomixed">[Spolsky] Joel Spolsky, &quot;The Project
Aardvark Spec&quot;, August 2005, <span class="bibliomisc"><a href=
"http://www.joelonsoftware.com/articles/AardvarkSpec.html" target=
"_top">http://www.joelonsoftware.com/articles/AardvarkSpec.html</a></span>.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
