<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"	>
<channel>
	<title>Comments on: Unit testing tricks: Look ma, no setters!</title>
	<atom:link href="http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/feed/" rel="self" type="application/rss+xml" />
	<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/</link>
	<description>Johannes Brodwall&#039;s Musings on Software Architecture and Programming</description>
	<lastBuildDate>Fri, 12 Mar 2010 19:22:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Johannes Brodwall</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-127612</link>
		<dc:creator>Johannes Brodwall</dc:creator>
		<pubDate>Wed, 17 Jun 2009 21:42:40 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-127612</guid>
		<description>True. The reason they ended up as protected is that that&#039;s what happens if you just do &quot;Ctrl-1&quot; in Eclipse. ;-)&lt;br&gt;&lt;br&gt;This example requires a no-arg constructor, but if Account only had, say, a constructor &quot;Account(String accountNumber)&quot;, you could just do &lt;code&gt;new Account(&quot;12345678901&quot;) {{&lt;/code&gt; and the rest would be the same.</description>
		<content:encoded><![CDATA[<p>True. The reason they ended up as protected is that that&#39;s what happens if you just do &#8220;Ctrl-1&#8243; in Eclipse. ;-)</p>
<p>This example requires a no-arg constructor, but if Account only had, say, a constructor &#8220;Account(String accountNumber)&#8221;, you could just do <code>new Account("12345678901") {{</code> and the rest would be the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhannes</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125529</link>
		<dc:creator>jhannes</dc:creator>
		<pubDate>Wed, 17 Jun 2009 14:42:40 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125529</guid>
		<description>True. The reason they ended up as protected is that that&#039;s what happens if you just do &quot;Ctrl-1&quot; in Eclipse. ;-)&lt;br&gt;&lt;br&gt;This example requires a no-arg constructor, but if Account only had, say, a constructor &quot;Account(String accountNumber)&quot;, you could just do &lt;code&gt;new Account(&quot;12345678901&quot;) {{&lt;/code&gt; and the rest would be the same.</description>
		<content:encoded><![CDATA[<p>True. The reason they ended up as protected is that that&#39;s what happens if you just do &#8220;Ctrl-1&#8243; in Eclipse. ;-)</p>
<p>This example requires a no-arg constructor, but if Account only had, say, a constructor &#8220;Account(String accountNumber)&#8221;, you could just do <code>new Account("12345678901") {{</code> and the rest would be the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baard H. Rehn Johansen</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125456</link>
		<dc:creator>Baard H. Rehn Johansen</dc:creator>
		<pubDate>Tue, 16 Jun 2009 19:47:02 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125456</guid>
		<description>If the test-code is in the same package as Account you could use package-private fields instead of protected fields. In your example, Account also requires a no-arg constructor.</description>
		<content:encoded><![CDATA[<p>If the test-code is in the same package as Account you could use package-private fields instead of protected fields. In your example, Account also requires a no-arg constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Filip van Laenen</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125398</link>
		<dc:creator>Filip van Laenen</dc:creator>
		<pubDate>Mon, 15 Jun 2009 08:44:11 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125398</guid>
		<description>I think it would give less violation since it would only be a setter (a protected variable is basically a proetcted getter and a setter), and at the same time less confusing.</description>
		<content:encoded><![CDATA[<p>I think it would give less violation since it would only be a setter (a protected variable is basically a proetcted getter and a setter), and at the same time less confusing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhannes</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125397</link>
		<dc:creator>jhannes</dc:creator>
		<pubDate>Mon, 15 Jun 2009 07:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125397</guid>
		<description>Yes. But I thought that&#039;d give me as much violation of encapsulation, but with more code. If the setters were to be used by other code, I would&#039;ve gone that way, though.</description>
		<content:encoded><![CDATA[<p>Yes. But I thought that&#39;d give me as much violation of encapsulation, but with more code. If the setters were to be used by other code, I would&#39;ve gone that way, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Filip van Laenen</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125396</link>
		<dc:creator>Filip van Laenen</dc:creator>
		<pubDate>Mon, 15 Jun 2009 07:19:04 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125396</guid>
		<description>Have you considered adding a protected setter instead?</description>
		<content:encoded><![CDATA[<p>Have you considered adding a protected setter instead?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergio Bossa</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125395</link>
		<dc:creator>Sergio Bossa</dc:creator>
		<pubDate>Mon, 15 Jun 2009 06:59:34 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125395</guid>
		<description>Hi Johannes,&lt;br&gt;&lt;br&gt;it&#039;s a neat trick, but I still prefer to separate the domain object interface from its concrete implementation, and than add all required setters/getters to the latter.&lt;br&gt;&lt;br&gt;By doing so, if you program by interfaces your domain code will only see methods from the interface (so no breaking encapsulation), while you will be able to still use setters/getters in your test code (nothing bad about that, tests are there for testing actual implementations).&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;&lt;br&gt;Sergio B.</description>
		<content:encoded><![CDATA[<p>Hi Johannes,</p>
<p>it&#39;s a neat trick, but I still prefer to separate the domain object interface from its concrete implementation, and than add all required setters/getters to the latter.</p>
<p>By doing so, if you program by interfaces your domain code will only see methods from the interface (so no breaking encapsulation), while you will be able to still use setters/getters in your test code (nothing bad about that, tests are there for testing actual implementations).</p>
<p>Cheers,</p>
<p>Sergio B.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kristian Nordal</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125394</link>
		<dc:creator>Kristian Nordal</dc:creator>
		<pubDate>Mon, 15 Jun 2009 05:40:56 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125394</guid>
		<description>I like the &quot;trick&quot; with anonymous subclass + initialized block, and use it often. It&#039;s great when initializing collections.&lt;br&gt;&lt;br&gt;I&#039;m not sure about making the fields protected though. I don&#039;t like it when my tests affect/dictate visibility/accessibility.</description>
		<content:encoded><![CDATA[<p>I like the &#8220;trick&#8221; with anonymous subclass + initialized block, and use it often. It&#39;s great when initializing collections.</p>
<p>I&#39;m not sure about making the fields protected though. I don&#39;t like it when my tests affect/dictate visibility/accessibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vidar</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125393</link>
		<dc:creator>vidar</dc:creator>
		<pubDate>Mon, 15 Jun 2009 04:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125393</guid>
		<description>Nice. I have used a similar technique creating dummy classes that extends the class under test and override methods instead of using mocking. Next time I will definitely consider your approach. &lt;br&gt;&lt;br&gt;The &quot;dummy class&quot; technique is described in Robert Martin´s book Working Effectively with Legacy Code.</description>
		<content:encoded><![CDATA[<p>Nice. I have used a similar technique creating dummy classes that extends the class under test and override methods instead of using mocking. Next time I will definitely consider your approach. </p>
<p>The &#8220;dummy class&#8221; technique is described in Robert Martin´s book Working Effectively with Legacy Code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhannes</title>
		<link>http://johannesbrodwall.com/2009/06/14/unit-testing-tricks-look-ma-no-setters/comment-page-1/#comment-125351</link>
		<dc:creator>jhannes</dc:creator>
		<pubDate>Sun, 14 Jun 2009 18:19:15 +0000</pubDate>
		<guid isPermaLink="false">http://brodwall.com/johannes/blog/?p=366#comment-125351</guid>
		<description>The impact on the class under test is something that concerns me. In this particular case, we were debating whether to do this or use a inner builder class. They both felt slightly smelly, but at least this approach has the least code.&lt;br&gt;&lt;br&gt;When the problem starts to scale, I might consider builders, structs, introducing setters or something else. But it seems like a lot of extra code to write for the size of the problem.&lt;br&gt;&lt;br&gt;There&#039;s a lot of tools in the &quot;object initialization in test&quot; toolbox. I&#039;m still not thrilled with any of them.</description>
		<content:encoded><![CDATA[<p>The impact on the class under test is something that concerns me. In this particular case, we were debating whether to do this or use a inner builder class. They both felt slightly smelly, but at least this approach has the least code.</p>
<p>When the problem starts to scale, I might consider builders, structs, introducing setters or something else. But it seems like a lot of extra code to write for the size of the problem.</p>
<p>There&#39;s a lot of tools in the &#8220;object initialization in test&#8221; toolbox. I&#39;m still not thrilled with any of them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
