<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: TDD: Combining the when and then steps</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26863</link>
		<dc:creator>Mark Needham</dc:creator>
		<pubDate>Tue, 17 Nov 2009 14:12:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26863</guid>
		<description>That seems fine to me - it&#039;s still possible to understand what&#039;s going on in the test just from reading it and you haven&#039;t pulled out too much of the test into other methods.</description>
		<content:encoded><![CDATA[<p>That seems fine to me &#8211; it&#8217;s still possible to understand what&#8217;s going on in the test just from reading it and you haven&#8217;t pulled out too much of the test into other methods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26821</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 16 Nov 2009 12:18:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26821</guid>
		<description>Take for example

[code]
function testListAll()
    {
        $this-&gt;createMMY();
        $test1_id = $this-&gt;insertModel( $this-&gt;make_id, &#039;Y&#039; );
        $test2_id = $this-&gt;insertModel( $this-&gt;make_id, &#039;Z&#039; );
        $model = $this-&gt;findModelById( $this-&gt;model_id );
        $expected = array();
        $expected[0] = $this-&gt;findModelById( $this-&gt;model_id );
        $expected[1] = $this-&gt;findModelById( $test1_id );
        $expected[2] = $this-&gt;findModelById( $test2_id );
        $this-&gt;assertEquals( $expected, $model-&gt;listAll(), &#039;should return exactly the right items, in alphabetical order, and nothing more&#039; );
    }
[/code]

Becomes...

[code]
function testListAll()
    {
        // fixture
        list( $inserted_id1, $inserted_id2 ) = $this-&gt;createMMYWithAddtModels();
        // SUT
        $model = $this-&gt;findModelById( $this-&gt;model_id );
        // verify!
        $expected = $this-&gt;getEntities( $this-&gt;model_id, $inserted_id1, $inserted_id2 );
        $this-&gt;assertEquals( $expected, $model-&gt;listAll(), &#039;should return exactly the right items, in alphabetical order, and nothing more&#039; );
    }
[/code]</description>
		<content:encoded><![CDATA[<p>Take for example</p>
<p>[code]<br />
function testListAll()<br />
    {<br />
        $this-&gt;createMMY();<br />
        $test1_id = $this-&gt;insertModel( $this-&gt;make_id, 'Y' );<br />
        $test2_id = $this-&gt;insertModel( $this-&gt;make_id, 'Z' );<br />
        $model = $this-&gt;findModelById( $this-&gt;model_id );<br />
        $expected = array();<br />
        $expected[0] = $this-&gt;findModelById( $this-&gt;model_id );<br />
        $expected[1] = $this-&gt;findModelById( $test1_id );<br />
        $expected[2] = $this-&gt;findModelById( $test2_id );<br />
        $this-&gt;assertEquals( $expected, $model-&gt;listAll(), 'should return exactly the right items, in alphabetical order, and nothing more' );<br />
    }<br />
[/code]</p>
<p>Becomes&#8230;</p>
<p>[code]<br />
function testListAll()<br />
    {<br />
        // fixture<br />
        list( $inserted_id1, $inserted_id2 ) = $this-&gt;createMMYWithAddtModels();<br />
        // SUT<br />
        $model = $this-&gt;findModelById( $this-&gt;model_id );<br />
        // verify!<br />
        $expected = $this-&gt;getEntities( $this-&gt;model_id, $inserted_id1, $inserted_id2 );<br />
        $this-&gt;assertEquals( $expected, $model-&gt;listAll(), 'should return exactly the right items, in alphabetical order, and nothing more' );<br />
    }<br />
[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26819</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 16 Nov 2009 12:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26819</guid>
		<description>You should also factor out duplication into creation methods that accept as parameters, values that are relevant to the outcome of that particular test.</description>
		<content:encoded><![CDATA[<p>You should also factor out duplication into creation methods that accept as parameters, values that are relevant to the outcome of that particular test.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26818</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 16 Nov 2009 12:02:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26818</guid>
		<description>I disagree with you, test code duplication is bad and causes all the same problems it causes in production, however unlike production code it is not as high of a priority, there is a higher priority which is tests as documentation (which is why it should have been moved in your example).

If you are duplicating data that does not affect the outcome of the test, then you move it out of the test method so we say to the reader &quot;the value you do not see do not affect the outcome values&quot; - XUnit Testing Patterns</description>
		<content:encoded><![CDATA[<p>I disagree with you, test code duplication is bad and causes all the same problems it causes in production, however unlike production code it is not as high of a priority, there is a higher priority which is tests as documentation (which is why it should have been moved in your example).</p>
<p>If you are duplicating data that does not affect the outcome of the test, then you move it out of the test method so we say to the reader &#8220;the value you do not see do not affect the outcome values&#8221; &#8211; XUnit Testing Patterns</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #477</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26809</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #477</dc:creator>
		<pubDate>Mon, 16 Nov 2009 08:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26809</guid>
		<description>[...] TDD: Combining the when and then steps - Mark Needham talks about how a strict adherence to the DRY (Don&#8217;t repeat yourself) Principle in Unit Tests can result in less readable tests. Mark also issues A reminder to talk to the rubber duck, a useful technique which I refer to as the &#8216;Code Bear&#8217;, where simply expressing the problem you are having leads to a solution [...]</description>
		<content:encoded><![CDATA[<p>[...] TDD: Combining the when and then steps &#8211; Mark Needham talks about how a strict adherence to the DRY (Don&#8217;t repeat yourself) Principle in Unit Tests can result in less readable tests. Mark also issues A reminder to talk to the rubber duck, a useful technique which I refer to as the &#8216;Code Bear&#8217;, where simply expressing the problem you are having leads to a solution [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Marbach</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26766</link>
		<dc:creator>Daniel Marbach</dc:creator>
		<pubDate>Sat, 14 Nov 2009 15:25:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26766</guid>
		<description>I would prefer the following structure:

@Test
public void WhenOriginalValueAndNewValueAreEqualCalculatedPercentageMustBeZero() {
   const int originalValue = 100;
   const int newValue = 100;
   const int expectedPercentageDifference = 0;

   PercentageCalculator testee = this.createTestee();

assertEquals(expectedPercentageDifference ,testee.calculatePercentage(originalValue, newValue)
}

@Test
public void WhenOriginalValueIsHalfOfNewValueCalculatedPercentageMustBeOneHundred() {
   const int originalValue = 50;
   const int newValue = 100;
   const int expectedPercentageDifference = 100;

   PercentageCalculator testee = this.createTestee();

assertEquals(expectedPercentageDifference ,testee.calculatePercentage(originalValue, newValue)
}

and so one...

private PercentageCalculator createTestee() {
   return new PercentageCalculator();
}</description>
		<content:encoded><![CDATA[<p>I would prefer the following structure:</p>
<p>@Test<br />
public void WhenOriginalValueAndNewValueAreEqualCalculatedPercentageMustBeZero() {<br />
   const int originalValue = 100;<br />
   const int newValue = 100;<br />
   const int expectedPercentageDifference = 0;</p>
<p>   PercentageCalculator testee = this.createTestee();</p>
<p>assertEquals(expectedPercentageDifference ,testee.calculatePercentage(originalValue, newValue)<br />
}</p>
<p>@Test<br />
public void WhenOriginalValueIsHalfOfNewValueCalculatedPercentageMustBeOneHundred() {<br />
   const int originalValue = 50;<br />
   const int newValue = 100;<br />
   const int expectedPercentageDifference = 100;</p>
<p>   PercentageCalculator testee = this.createTestee();</p>
<p>assertEquals(expectedPercentageDifference ,testee.calculatePercentage(originalValue, newValue)<br />
}</p>
<p>and so one&#8230;</p>
<p>private PercentageCalculator createTestee() {<br />
   return new PercentageCalculator();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Cook</title>
		<link>http://www.markhneedham.com/blog/2009/11/14/tdd-combining-the-when-and-then-steps/comment-page-1/#comment-26730</link>
		<dc:creator>Bryan Cook</dc:creator>
		<pubDate>Fri, 13 Nov 2009 14:39:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1819#comment-26730</guid>
		<description>I had the exact same argument with a developer the other day.  Concise, elegant tests are great, but there comes a point where abstracting away test details limits our ability to understand the structure of the code itself.</description>
		<content:encoded><![CDATA[<p>I had the exact same argument with a developer the other day.  Concise, elegant tests are great, but there comes a point where abstracting away test details limits our ability to understand the structure of the code itself.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

