<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Tom Moertel's Weblog: Unit testing is a tool, not a goal</title>
    <link>http://blog.moertel.com/articles/2006/10/10/unit-testing-is-a-tool-not-a-goal</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Quality rants on programming theory and stuff geeks like</description>
    <item>
      <title>Unit testing is a tool, not a goal</title>
      <description>&lt;p&gt;Via the ever-entertaining
&lt;a href="http://programming.reddit.com"&gt;programming.reddit.com&lt;/a&gt;, I discovered
&lt;a href="http://blogs.concedere.net:8080/blog/discipline/software+engineering/?permalink=The-Misguided-Faith-in-Unit-Tests.html"&gt;The (Misguided?) Faith in Unit
Tests&lt;/a&gt;.
I don&amp;#8217;t agree with the article&amp;#8217;s thesis, but the article did hit
upon a grain of unfortunate truth: many unit-testing practitioners
have a rather cultish aspect to their devotion.  More and more, people
push unit testing not because it&amp;#8217;s an inexpensive way to establish a lot of
confidence in our code&amp;#8217;s correctness, but because it&amp;#8217;s &amp;#8220;good&amp;#8221; or &amp;#8220;a
best practice&amp;#8221; or &amp;#8220;professional.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;When unit testing becomes an end in itself, something has gone
haywire. Software-development practices, including unit testing, are
just tools.  No one tool is the solution to all problems.  To the
extent that we over-apply any particular tool, we cheat ourselves.  We
miss out on the opportunity to use other, more effective tools.&lt;/p&gt;


	&lt;p&gt;My favorite example of a common, important kind of problem that unit
testing isn&amp;#8217;t much help for is the
&amp;#8220;strings problem.&amp;#8221;  All those &lt;a href="http://en.wikipedia.org/wiki/Cross_site_scripting" title="XSS"&gt;cross-site-scripting&lt;/a&gt;
vulnerabilities and
&lt;a href="http://en.wikipedia.org/wiki/SQL_injection"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt;-injection&lt;/a&gt; holes you
have been reading about in recent days are prime examples.  In short,
the strings problem is having to keep track of and escape, as needed,
the bazillion types of strings that flow as life-blood within the
arteries of modern web applications.&lt;/p&gt;


	&lt;p&gt;Trying to detect string-escaping problems via unit testing is costly
because it&amp;#8217;s at least as difficult to write the tests correctly as it
is to write the code the tests are testing.  Further, a
programmer who forgets that he needs to escape user-supplied strings
before stuffing them into live web pages isn&amp;#8217;t going to remember to
write tests for his having forgotten to escape the strings.&lt;/p&gt;


	&lt;p&gt;If, then, you come to the programming party with the preconceived
notion that unit testing is the only way to go, there&amp;#8217;s a pretty good
chance that your web applications are going to be sporting some &lt;span class="caps"&gt;XSS&lt;/span&gt; or
&lt;span class="caps"&gt;SQL&lt;/span&gt;-injection holes.  On the other hand, if you view unit testing as a
tool, you&amp;#8217;re likely to consider the possibility that other tools might
be more effective for something like the strings problem.  You might,
for example, decide to use a type-system-based
solution, which pretty much makes the strings problem trivial to solve.
(I&amp;#8217;ll write about solving the strings problem in Haskell in an
upcoming article.)&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not saying that unit testing is &amp;#8220;bad&amp;#8221; or that it&amp;#8217;s not &amp;#8220;good.&amp;#8221; 
What I&amp;#8217;m saying is that &lt;em&gt;unit testing is not the goal&lt;/em&gt;.  The goal is
having confidence in your code doing what it ought to do.  Unit
testing is often an inexpensive way to achieve much of that confidence,
but for many situations, the strings problem being one of them, it
pays to keep an open mind about supplementing unit testing with other
tools.&lt;/p&gt;


&lt;div class="update"&gt;
&lt;strong&gt;Update:&lt;/strong&gt; Minor edits for readability.
&lt;/div&gt;</description>
      <pubDate>Tue, 10 Oct 2006 15:23:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:4578342f-daba-436c-9163-e20694d29cde</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2006/10/10/unit-testing-is-a-tool-not-a-goal</link>
      <category>programming</category>
      <category>testing</category>
      <category>testing</category>
      <category>culture</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/182</trackback:ping>
    </item>
  </channel>
</rss>
