<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.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>Object Mentor Blog: Unit Tests Coverage: Less Is More</title>
    <link>http://blog.objectmentor.com/articles/2007/05/07/unit-tests-coverage-less-is-more</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Unit Tests Coverage: Less Is More</title>
      <description>&lt;p&gt;In &lt;span class="caps"&gt;TDD&lt;/span&gt; a unit test has to be very small to isolate failures.  This does funny things to code coverage as a metric.  Each test should have a very small area of effect, and so each unit test should have a negligible effect on the overall code coverage statistic.  Bear with me here, see where I&amp;#8217;m missing out.&lt;/p&gt;


	&lt;p&gt;Say you have an existing (legacy) system with no coverage at all.  Zero percent.  If you start doing &lt;span class="caps"&gt;TDD&lt;/span&gt; today, the overall coverage percentage should barely change at all. If only the new code is test-driven, then the old code is not gaining coverage except where tests are necessary to ensure that the new code is being called.  The low coverage per test is a good thing because it shows that the unit tests have good isolation.  In such a situation, code coverage is really telling you the ratio of new code to old code.  Again, this is so obvious and logical to me that I must be missing some cool subtleties.&lt;/p&gt;


	&lt;p&gt;If all the code was test-driven from the beginning, you should have a very high coverage number, and writing a new unit test &lt;strong&gt;before&lt;/strong&gt; you add code should not impact that number.  You only write enough code to pass the test, so again you aren&amp;#8217;t getting much in the way of uncovered code. A lowering of the ratio might indicate a problem with test-to-production-code ratio.  This seems pretty simple and logical, so I&amp;#8217;m sure I&amp;#8217;m missing some interesting corner cases.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;OTOH&lt;/span&gt;, system tests and integration tests paths through many components at once, and should have a more significant effect on coverage in a previously-untested system, though their job is to prove function points, not to raise the metrics.  These non-unit tests are the thing that boost your coverage of old code. That is also a good effect, because it is the goal of the system test to ensure that the parts work together.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not saying that code coverage should be low, only that as we move incrementally, the unit tests we write should individually have negligible effect on our overall code coverage numbers&amp;#8230; a thought that intrigues me.&lt;/p&gt;</description>
      <pubDate>Mon, 07 May 2007 08:06:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1bd6fe5d-c5ff-4269-a20d-87e7d57443d8</guid>
      <author>Tim Ottinger</author>
      <link>http://blog.objectmentor.com/articles/2007/05/07/unit-tests-coverage-less-is-more</link>
      <category>Tim's Tepid Torrent</category>
    </item>
    <item>
      <title>"Unit Tests Coverage: Less Is More" by Tim</title>
      <description>&lt;p&gt;Of course.  But even then, your test shouldn&amp;#8217;t change the total coverage percentage by much.  It matters more than it shows, which is my problem with coverage in general.&lt;/p&gt;


	&lt;p&gt;You can show progress by bumping up the coverage number, but your tests don&amp;#8217;t have to be any good.  But if you write good tests where they&amp;#8217;re needed (as given by Lindsay) then you have the real goal covered, but the prosthetic goal is largely untouched.&lt;/p&gt;


	&lt;p&gt;Coverage grows very slowly in legacy code.&lt;/p&gt;</description>
      <pubDate>Mon, 06 Aug 2007 10:32:35 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c0ba4018-f756-4da7-b88d-2d5b89663dcc</guid>
      <link>http://blog.objectmentor.com/articles/2007/05/07/unit-tests-coverage-less-is-more#comment-588</link>
    </item>
    <item>
      <title>"Unit Tests Coverage: Less Is More" by Lindsay</title>
      <description>&lt;p&gt;Of course in a Test Driven Context, the first stage in fixing a bug is writing a test to expose it, so you should end up with some coverage of old code.&lt;/p&gt;</description>
      <pubDate>Mon, 06 Aug 2007 07:44:31 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4a8da19c-67c1-4b6e-8990-d88b21b56010</guid>
      <link>http://blog.objectmentor.com/articles/2007/05/07/unit-tests-coverage-less-is-more#comment-585</link>
    </item>
  </channel>
</rss>
