<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Coverage != testing</title>
	<link>http://tech.puredanger.com/2007/11/14/coverage-testing/</link>
	<description>Alex Miller's technical blog</description>
	<pubDate>Thu, 28 Aug 2008 03:09:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Alex Miller - Practical unit testing</title>
		<link>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-28700</link>
		<pubDate>Sat, 23 Feb 2008 04:36:05 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-28700</guid>
					<description>[...] I was reading Howard&amp;#8217;s post today on his crisis of faith with respect to unit testing and it launched an interesting conversation with a colleague. I&amp;#8217;m a unit testing advocate. But I&amp;#8217;m not a big fan of test-first or test-driven development (TDD). And I&amp;#8217;m not a believer in 100% coverage. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] I was reading Howard&#8217;s post today on his crisis of faith with respect to unit testing and it launched an interesting conversation with a colleague. I&#8217;m a unit testing advocate. But I&#8217;m not a big fan of test-first or test-driven development (TDD). And I&#8217;m not a believer in 100% coverage. [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Scott Bale</title>
		<link>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-23085</link>
		<pubDate>Thu, 24 Jan 2008 23:37:01 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-23085</guid>
					<description>I want to add my 2 cents here, as I've been thinking about this topic again as I've been retroactively adding tests to others' existing code.

This has basically been said already above, but I'm impressed once again that, when doing &quot;test after&quot; like I'm doing this week, and when tackling a codebase that is not easily testable, I find myself writing long and complicated test fixture setups just to enable a single test with a single assert.  The side effect is that all that setup covers a lot of code, but does **not** test it.  This is a little scary to me, that even if someone with good intentions tries to retroactively add tests to legacy code like I am doing, it's almost unavoidable that the resulting coverage stats will be skewed due to the aforementioned complexity in test fixture setup.  As Julio stated, and I heartily agree, with TDD in theory you can have much more confidence in raw coverage statistics, since every line of production code should be backed by at least one test.  But if you find yourself in a situation like I'm in I'm not sure what can be done other than to be very skeptical of test coverage stats at all.  And, as Kent Beck says, to write the tests you wish you had.

re: code generators, in response to Eric and Alex, I hadn't really thought about it before, but I would be in favor of generating tests for simple getters/setters if for no other reason than they would be great, obvious placesetters for future tests if and when (as Alex said) the getters or setters had to change to have more complex behavior.  I don't feel any particular need to have n-percent code coverage, but I am in favor of doing anything that eases other developers' future enhancement/maintenance of a codebase I work on.</description>
		<content:encoded><![CDATA[<p>I want to add my 2 cents here, as I&#8217;ve been thinking about this topic again as I&#8217;ve been retroactively adding tests to others&#8217; existing code.</p>
<p>This has basically been said already above, but I&#8217;m impressed once again that, when doing &#8220;test after&#8221; like I&#8217;m doing this week, and when tackling a codebase that is not easily testable, I find myself writing long and complicated test fixture setups just to enable a single test with a single assert.  The side effect is that all that setup covers a lot of code, but does **not** test it.  This is a little scary to me, that even if someone with good intentions tries to retroactively add tests to legacy code like I am doing, it&#8217;s almost unavoidable that the resulting coverage stats will be skewed due to the aforementioned complexity in test fixture setup.  As Julio stated, and I heartily agree, with TDD in theory you can have much more confidence in raw coverage statistics, since every line of production code should be backed by at least one test.  But if you find yourself in a situation like I&#8217;m in I&#8217;m not sure what can be done other than to be very skeptical of test coverage stats at all.  And, as Kent Beck says, to write the tests you wish you had.</p>
<p>re: code generators, in response to Eric and Alex, I hadn&#8217;t really thought about it before, but I would be in favor of generating tests for simple getters/setters if for no other reason than they would be great, obvious placesetters for future tests if and when (as Alex said) the getters or setters had to change to have more complex behavior.  I don&#8217;t feel any particular need to have n-percent code coverage, but I am in favor of doing anything that eases other developers&#8217; future enhancement/maintenance of a codebase I work on.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: The Disco Blog &#187; Blog Archive &#187; The weekly bag&#8211; Nov 16</title>
		<link>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14773</link>
		<pubDate>Wed, 21 Nov 2007 18:57:07 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14773</guid>
					<description>[...] Coverage != testing- I couldn&amp;#8217;t agree more, man. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Coverage != testing- I couldn&#8217;t agree more, man. [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Alex</title>
		<link>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14036</link>
		<pubDate>Thu, 15 Nov 2007 16:39:59 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14036</guid>
					<description>@Julio, points fairly made, although I disagree.  

I think the main point is that simply calling a method (coverage) does not verify anything about whether it did the right thing.  And there are lots of ways for indirect coverage (from testing another method) to execute a method without actually testing it.  This can give you a false sense of security that coverage == testing.  In the case of test-first, you're right that theoretically every method should have an associated test.  However, the overwhelming majority of developers do not work test-first.  

The comments were made in the context of testing &quot;simple&quot; getters and setters, and in that case I think I could make an argument that writing a bunch of tests like:

&lt;pre&gt;
public void testGetName() {
  Person p = new Person();
  p.setName(&quot;SpongeBob&quot;);
  assertEquals(&quot;SpongeBob&quot;, p.getName());
}
&lt;/pre&gt;

for auto-generated get/set methods is testing for the sake of coverage.  Now, if that setter is doing a bunch of name validation or the getter is actually fronting a cache or talking to a database or constructing the name from multiple fields or something, then by all means test it.

My experience has been that 75-80% coverage is where the rate of return falls off considerably.  That is to say, coverage beyond that point is valuable, but is not valuable enough to justify the effort.  Note, that that target is an average.  For really important or critical or complex stuff, I would strive for something much higher.  And for less important code I would shoot for something lower.</description>
		<content:encoded><![CDATA[<p>@Julio, points fairly made, although I disagree.  </p>
<p>I think the main point is that simply calling a method (coverage) does not verify anything about whether it did the right thing.  And there are lots of ways for indirect coverage (from testing another method) to execute a method without actually testing it.  This can give you a false sense of security that coverage == testing.  In the case of test-first, you&#8217;re right that theoretically every method should have an associated test.  However, the overwhelming majority of developers do not work test-first.  </p>
<p>The comments were made in the context of testing &#8220;simple&#8221; getters and setters, and in that case I think I could make an argument that writing a bunch of tests like:</p>
<pre>
public void testGetName() {
  Person p = new Person();
  p.setName("SpongeBob");
  assertEquals("SpongeBob", p.getName());
}
</pre>
<p>for auto-generated get/set methods is testing for the sake of coverage.  Now, if that setter is doing a bunch of name validation or the getter is actually fronting a cache or talking to a database or constructing the name from multiple fields or something, then by all means test it.</p>
<p>My experience has been that 75-80% coverage is where the rate of return falls off considerably.  That is to say, coverage beyond that point is valuable, but is not valuable enough to justify the effort.  Note, that that target is an average.  For really important or critical or complex stuff, I would strive for something much higher.  And for less important code I would shoot for something lower.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Julio Santos</title>
		<link>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14031</link>
		<pubDate>Thu, 15 Nov 2007 15:54:17 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/11/14/coverage-testing/#comment-14031</guid>
					<description>You use a strawman argument in my opinion. First you're responding to someone who's advocating test first. You everything you do is test first, you don't need to worry about coverage, you will have it by simple definition of doing tests first.

I must admit I'm guilty of being a 100%-coverage advocate, and trying hard to get there (98% on my current project). In part because I know I make mistakes and in part because 90% of my nastiest bugs are in the un-covered few percent.

More importantly to your point, and why it's a strawman argument, is that I have never seen anyone writing tests that don't test anything (or the wrong thing) just for he sake of coverage. No one is writing &quot;assert_equal 3, calc.add(1,1)&quot; just so calc gets coverage. So yes, in practice coverage == testing.</description>
		<content:encoded><![CDATA[<p>You use a strawman argument in my opinion. First you&#8217;re responding to someone who&#8217;s advocating test first. You everything you do is test first, you don&#8217;t need to worry about coverage, you will have it by simple definition of doing tests first.</p>
<p>I must admit I&#8217;m guilty of being a 100%-coverage advocate, and trying hard to get there (98% on my current project). In part because I know I make mistakes and in part because 90% of my nastiest bugs are in the un-covered few percent.</p>
<p>More importantly to your point, and why it&#8217;s a strawman argument, is that I have never seen anyone writing tests that don&#8217;t test anything (or the wrong thing) just for he sake of coverage. No one is writing &#8220;assert_equal 3, calc.add(1,1)&#8221; just so calc gets coverage. So yes, in practice coverage == testing.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
