<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Why unit tests are&#160;important</title>
	<atom:link href="http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/</link>
	<description>Sam Newman's blog</description>
	<pubDate>Fri, 08 Aug 2008 18:59:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-935</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Thu, 22 Sep 2005 09:02:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-935</guid>
		<description>Simon Wrote:
&#62; Accessors are typically get/set pairs, 
&#62; and I always test them at the same time in
&#62; the same test.

Which is fine as it goes, but I'm wary of describing get/set pairs as behaviour - a bucket of data has little in the way of behaviour :-)

&#62; Master/Detail relationships are another.
&#62; It's easy to test the Detail in isolation, 
&#62;but how do I test the Master without a Detail
&#62; or Two?
&#62;
&#62; Just a thought. :-)

And that is where mock objects come into play. When you test A, you want to test that it acts with B and C in an expected way (e.g.  when I call email on a group object, I expect it to contact the report generator and then the email server).

&#62; So write your FileConfiguration class so it 
&#62; takes a io stream or a file name. Then you can 
&#62; test 99% of the functionality, probably the most
&#62;  important functionality, without touching the 
&#62; file system. 

&#62; As I recall one of Feather's points was 
&#62; that if you cannot write a proper unit 
&#62; test, then maybe the design needs work.

His points where to encourage discussion, to to enforce rigid rules. In an environment where people are unsure of what and how to test, rigid adherence to a set of guidelines is useful - one people understand the concepts they understand where it is ok to ignore them. If a single classes job is to locate a named property file on the classpath, and throw a runtime exception if it doesn't exist and it needs the use of no other (non-core) classes, I have to test it actually loading a file. I could wrap and mock the IO system I suppose, but then I'd need to test the IO wrapper - and that seems overkill for a class that loads a property file.


</description>
		<content:encoded><![CDATA[<p>Simon Wrote:<br />
> Accessors are typically get/set pairs, <br />
> and I always test them at the same time in<br />
> the same test.</p>
<p>Which is fine as it goes, but I&#8217;m wary of describing get/set pairs as behaviour &#8211; a bucket of data has little in the way of behaviour :-)</p>
<p>> Master/Detail relationships are another.<br />
> It&#8217;s easy to test the Detail in isolation, <br />
>but how do I test the Master without a Detail<br />
> or Two?<br />
><br />
> Just a thought. :-)</p>
<p>And that is where mock objects come into play. When you test A, you want to test that it acts with B and C in an expected way (e.g.  when I call email on a group object, I expect it to contact the report generator and then the email server).</p>
<p>> So write your FileConfiguration class so it <br />
> takes a io stream or a file name. Then you can <br />
> test 99% of the functionality, probably the most<br />
>  important functionality, without touching the <br />
> file system. </p>
<p>> As I recall one of Feather&#8217;s points was <br />
> that if you cannot write a proper unit <br />
> test, then maybe the design needs work.</p>
<p>His points where to encourage discussion, to to enforce rigid rules. In an environment where people are unsure of what and how to test, rigid adherence to a set of guidelines is useful &#8211; one people understand the concepts they understand where it is ok to ignore them. If a single classes job is to locate a named property file on the classpath, and throw a runtime exception if it doesn&#8217;t exist and it needs the use of no other (non-core) classes, I have to test it actually loading a file. I could wrap and mock the IO system I suppose, but then I&#8217;d need to test the IO wrapper &#8211; and that seems overkill for a class that loads a property file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RIchard Hansen</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-934</link>
		<dc:creator>RIchard Hansen</dc:creator>
		<pubDate>Wed, 21 Sep 2005 13:55:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-934</guid>
		<description>So write your FileConfiguration class so it takes a io stream or a file name. Then you can test 99% of the functionality, probably the most important functionality, without touching the file system. As I recall one of Feather's points was that if you cannot write a proper unit test, then maybe the design needs work.</description>
		<content:encoded><![CDATA[<p>So write your FileConfiguration class so it takes a io stream or a file name. Then you can test 99% of the functionality, probably the most important functionality, without touching the file system. As I recall one of Feather&#8217;s points was that if you cannot write a proper unit test, then maybe the design needs work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon P. Chappell</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-933</link>
		<dc:creator>Simon P. Chappell</dc:creator>
		<pubDate>Wed, 21 Sep 2005 13:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-933</guid>
		<description>I prefer to think/define unit tests in terms of testing a behaviour. Usually that behaviour is implemented in one method of one class, but this is not always the case.

Accessors are typically get/set pairs, and I always test them at the same time in the same test.

Master/Detail relationships are another. It's easy to test the Detail in isolation, but how do I test the Master without a Detail or Two?

Just a thought. :-)</description>
		<content:encoded><![CDATA[<p>I prefer to think/define unit tests in terms of testing a behaviour. Usually that behaviour is implemented in one method of one class, but this is not always the case.</p>
<p>Accessors are typically get/set pairs, and I always test them at the same time in the same test.</p>
<p>Master/Detail relationships are another. It&#8217;s easy to test the Detail in isolation, but how do I test the Master without a Detail or Two?</p>
<p>Just a thought. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-932</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Mon, 19 Sep 2005 09:07:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-932</guid>
		<description>Cedric Wrote:

&#62; I add a functionality, I test it. Period.
&#62;
&#62; It doesn't matter to me whether this 
&#62; functionality is user-facing or just an 
&#62; internal detail. If it can prevent the 
&#62; product from working the way the user 
&#62; expects it or the way it's documented, it
&#62; needs to have a test. Any test.

But my point was that by not having a fine-grained unit test you loose much of the benifits of testing at this level (and therefore many of the benifits of TDD), namely:

* promoting loosly coupled, highly cohesive code
*  small units of code with good test coverage promoting frequent checkins
* small units of code with good test coverage promote refactoring at a small level
* Testing at a smaller scope makes it easy to  cover all execution paths
* Large scale tests seem to promote state-based testing rather than testing of the design - less mocking, more asking - which isn't going to help a tell don't ask OO design.

Without some mental note to "only test one class at a time" you'll quickly find any team writing tests for a larger and larger scope.

Michael Wrote:

&#62; By all means, write the test. The point is 
&#62; really to think about what could be tested 
&#62; independently of the file system. Defining 
&#62; 'unit tests' narrowly, like I do with teams,
&#62; is really an invitation to think about that 
&#62; issue.

Agreed - it comes back to rules being there for the guidance of the wise and the obidience of fools I suppose.</description>
		<content:encoded><![CDATA[<p>Cedric Wrote:</p>
<p>> I add a functionality, I test it. Period.<br />
><br />
> It doesn&#8217;t matter to me whether this <br />
> functionality is user-facing or just an <br />
> internal detail. If it can prevent the <br />
> product from working the way the user <br />
> expects it or the way it&#8217;s documented, it<br />
> needs to have a test. Any test.</p>
<p>But my point was that by not having a fine-grained unit test you loose much of the benifits of testing at this level (and therefore many of the benifits of TDD), namely:</p>
<ul>
<li>promoting loosly coupled, highly cohesive code</li>
<li> small units of code with good test coverage promoting frequent checkins</li>
<li>small units of code with good test coverage promote refactoring at a small level</li>
<li>Testing at a smaller scope makes it easy to  cover all execution paths</li>
<li>Large scale tests seem to promote state-based testing rather than testing of the design &#8211; less mocking, more asking &#8211; which isn&#8217;t going to help a tell don&#8217;t ask OO design.</li>
</ul>
<p>Without some mental note to &#8220;only test one class at a time&#8221; you&#8217;ll quickly find any team writing tests for a larger and larger scope.</p>
<p>Michael Wrote:</p>
<p>> By all means, write the test. The point is <br />
> really to think about what could be tested <br />
> independently of the file system. Defining <br />
> &#8216;unit tests&#8217; narrowly, like I do with teams,<br />
> is really an invitation to think about that <br />
> issue.</p>
<p>Agreed &#8211; it comes back to rules being there for the guidance of the wise and the obidience of fools I suppose.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Feathers</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-931</link>
		<dc:creator>Michael Feathers</dc:creator>
		<pubDate>Mon, 19 Sep 2005 02:10:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-931</guid>
		<description>Michael's rules on what a unit test is seem overly draconian to some (not being able to touch the filesystem for example. 99% of the time I'd agree, but if I'm testing my FileConfiguration class, what the hell am I supposed to do?)?
-
By all means, write the test.  The point is really to think about what could be tested independently of the file system.  Defining 'unit tests' narrowly, like I do with teams, is really an invitation to think about that issue.</description>
		<content:encoded><![CDATA[<p>Michael&#8217;s rules on what a unit test is seem overly draconian to some (not being able to touch the filesystem for example. 99% of the time I&#8217;d agree, but if I&#8217;m testing my FileConfiguration class, what the hell am I supposed to do?)? &#8211; By all means, write the test.  The point is really to think about what could be tested independently of the file system.  Defining &#8216;unit tests&#8217; narrowly, like I do with teams, is really an invitation to think about that issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://www.magpiebrain.com/blog/2005/09/18/why-unit-tests-are-important/#comment-930</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Sun, 18 Sep 2005 23:47:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2005/09/18/why-unit-tests-are-important/#comment-930</guid>
		<description>If you want to see how scary my code is, just sync to TetsNG's CVS head and decide for yourself :-)

Here is a follow-up challenge:  among all the TestNG tests that you'll find there, count how many are unit tests and how many are not.

I wrote most of these tests myself and to be honest, I have no idea what the answer to this question is, and actually, I believe that it doesn't matter at all.

I add a functionality, I test it.  Period.

It doesn't matter to me whether this functionality is user-facing or just an internal detail.  If it can prevent the product from working the way the user expects it or the way it's documented, it needs to have a test.  Any test.</description>
		<content:encoded><![CDATA[<p>If you want to see how scary my code is, just sync to TetsNG&#8217;s <acronym title="Concurrent Versions System">CVS</acronym> head and decide for yourself :-)</p>
<p>Here is a follow-up challenge:  among all the TestNG tests that you&#8217;ll find there, count how many are unit tests and how many are not.</p>
<p>I wrote most of these tests myself and to be honest, I have no idea what the answer to this question is, and actually, I believe that it doesn&#8217;t matter at all.</p>
<p>I add a functionality, I test it.  Period.</p>
<p>It doesn&#8217;t matter to me whether this functionality is user-facing or just an internal detail.  If it can prevent the product from working the way the user expects it or the way it&#8217;s documented, it needs to have a test.  Any test.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
