<?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: Getters, Setters and the Great Coverage Conspiracy</title>
	<atom:link href="http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/</link>
	<description>Rants and opinion interspersed with awe-inspiring tales of heoric software engineering endeavours.</description>
	<lastBuildDate>Tue, 02 Mar 2010 10:03:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nick Pellow</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1253</link>
		<dc:creator>Nick Pellow</dc:creator>
		<pubDate>Fri, 11 Apr 2008 10:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1253</guid>
		<description>Great post, Dan!

I&#039;ve found bugs in my own code (and test cases) by seeing that certain setters or getters were not being called during testing. Had a unit test been written purely to cover those getters and setters, I most likely would not have found those bugs.

Unit tests which exist purely for the sake of increasing your code coverage can often do more harm than good.

@Fabrizio: Clover, (http://www.atlassian.com/software/clover/) provides Context Filters to have certain blocks of code excluded from your coverage figures. You can even define your own so you can exclude all getters/setters if you wish.

@Michael:
&quot;Finally, code-coverage should be able to report coverage percentages that either include or exclude getters and setters. Then one would know the wheat from the chaff.&quot;

The latest release of Clover (2.2.1) now reports on the percentage of your code that is excluded via a Context Filter, thus making it possible to do what you want. Have a look at the text below the stats in the header of this sample report
http://downloads.atlassian.com/software/clover/samples/checkstyle/index.html</description>
		<content:encoded><![CDATA[<p>Great post, Dan!</p>
<p>I&#8217;ve found bugs in my own code (and test cases) by seeing that certain setters or getters were not being called during testing. Had a unit test been written purely to cover those getters and setters, I most likely would not have found those bugs.</p>
<p>Unit tests which exist purely for the sake of increasing your code coverage can often do more harm than good.</p>
<p>@Fabrizio: Clover, (<a href="http://www.atlassian.com/software/clover/" rel="nofollow">http://www.atlassian.com/software/clover/</a>) provides Context Filters to have certain blocks of code excluded from your coverage figures. You can even define your own so you can exclude all getters/setters if you wish.</p>
<p>@Michael:<br />
&#8220;Finally, code-coverage should be able to report coverage percentages that either include or exclude getters and setters. Then one would know the wheat from the chaff.&#8221;</p>
<p>The latest release of Clover (2.2.1) now reports on the percentage of your code that is excluded via a Context Filter, thus making it possible to do what you want. Have a look at the text below the stats in the header of this sample report<br />
<a href="http://downloads.atlassian.com/software/clover/samples/checkstyle/index.html" rel="nofollow">http://downloads.atlassian.com/software/clover/samples/checkstyle/index.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: swv</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1241</link>
		<dc:creator>swv</dc:creator>
		<pubDate>Wed, 09 Apr 2008 21:27:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1241</guid>
		<description>Well to each his own- obviously there are two valid sides to this and I see not reason to pretend that&#039;s not so. 

Just to drop a bomb on this convo- I never, ever ever unit test. Not one line, not one class. Why? The historical reason is, I&#039;m a UI developer, most of my code is UI based so when unit testing hit, I went *sniff* ... *sniff*... hmmm....not for me...

Non-historically, I *really* think it&#039;s useless, though, as I say I&#039;ve never actually DONE it. I actually take it as a virtue that I could *sniff* ... *sniff* and decide it&#039;s silly pretty quickly and not look back (much.. or hard) .

 For me, it&#039;s one of those technologies that came along in a huff and frenzy, proclaimed the world was its stomping grounds, and gained a lot of adherents who spend a lot of time worshiping at its altar. A lot.

Here&#039;s my argument:

You&#039;re not going to pump water through all conceivable pipes because you can&#039;t. If you don&#039;t understand that (but yo probably do) you probably have some foundational CS still ahead of you, (just like most everyone else).  

In fact, you&#039;re only testing for use cases you can think of, which is what you programmed for in the first place. You&#039;re not *really* testing for anything outside of what you expect. In fact, if your code is clear, short simple well-named methods and coherent objects, you can go farther towards proving that your code will work as expected- farther than your unit test busy work will get you. 

Here&#039;s my Modus Operandi.. ...ready?

I look at each and every line of code and ask myself- why would this not do what&#039;s expected? Yep I sit there and and contemplate each line of code, and i say &quot;hmmm... what could possibly go wrong that doesn&#039;t represent a catastrophic failure on the part of either an outside library or the computer system?&quot;

And I leave little proof-notes  to myself in front of my methods which signify the reason why it can&#039;t go wrong. I have about 30 or so so far. I have the typing of them automated as macros in my IDE. 

I am never wrong. Ever. Over the course of 8 years, three since I&#039;ve been doing this, (before I was just really really careful)  three bugs have escaped me and gotten up to QA and one has shipped. And, no, I am not writing scripts for web pages or anything of that sort. My code is in Fortune 500s company-critical project offerings and the DOD. 

I never unit test because it&#039;s not the best way to ensure my code doesn&#039;t have bugs and it&#039;s not the best use of my brain power. Your intelligence and the understanding of the deep semantics of your program which only you can posses is far more able to detect bugs and many times more sensitive to bugs caused by an error in logic and unstated assumptions than unit tests are or are ever likely to be.  

I never unit test. 

Anything. 

Ever. 

So .... there.</description>
		<content:encoded><![CDATA[<p>Well to each his own- obviously there are two valid sides to this and I see not reason to pretend that&#8217;s not so. </p>
<p>Just to drop a bomb on this convo- I never, ever ever unit test. Not one line, not one class. Why? The historical reason is, I&#8217;m a UI developer, most of my code is UI based so when unit testing hit, I went *sniff* &#8230; *sniff*&#8230; hmmm&#8230;.not for me&#8230;</p>
<p>Non-historically, I *really* think it&#8217;s useless, though, as I say I&#8217;ve never actually DONE it. I actually take it as a virtue that I could *sniff* &#8230; *sniff* and decide it&#8217;s silly pretty quickly and not look back (much.. or hard) .</p>
<p> For me, it&#8217;s one of those technologies that came along in a huff and frenzy, proclaimed the world was its stomping grounds, and gained a lot of adherents who spend a lot of time worshiping at its altar. A lot.</p>
<p>Here&#8217;s my argument:</p>
<p>You&#8217;re not going to pump water through all conceivable pipes because you can&#8217;t. If you don&#8217;t understand that (but yo probably do) you probably have some foundational CS still ahead of you, (just like most everyone else).  </p>
<p>In fact, you&#8217;re only testing for use cases you can think of, which is what you programmed for in the first place. You&#8217;re not *really* testing for anything outside of what you expect. In fact, if your code is clear, short simple well-named methods and coherent objects, you can go farther towards proving that your code will work as expected- farther than your unit test busy work will get you. </p>
<p>Here&#8217;s my Modus Operandi.. &#8230;ready?</p>
<p>I look at each and every line of code and ask myself- why would this not do what&#8217;s expected? Yep I sit there and and contemplate each line of code, and i say &#8220;hmmm&#8230; what could possibly go wrong that doesn&#8217;t represent a catastrophic failure on the part of either an outside library or the computer system?&#8221;</p>
<p>And I leave little proof-notes  to myself in front of my methods which signify the reason why it can&#8217;t go wrong. I have about 30 or so so far. I have the typing of them automated as macros in my IDE. </p>
<p>I am never wrong. Ever. Over the course of 8 years, three since I&#8217;ve been doing this, (before I was just really really careful)  three bugs have escaped me and gotten up to QA and one has shipped. And, no, I am not writing scripts for web pages or anything of that sort. My code is in Fortune 500s company-critical project offerings and the DOD. </p>
<p>I never unit test because it&#8217;s not the best way to ensure my code doesn&#8217;t have bugs and it&#8217;s not the best use of my brain power. Your intelligence and the understanding of the deep semantics of your program which only you can posses is far more able to detect bugs and many times more sensitive to bugs caused by an error in logic and unstated assumptions than unit tests are or are ever likely to be.  </p>
<p>I never unit test. </p>
<p>Anything. </p>
<p>Ever. </p>
<p>So &#8230;. there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1240</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 09 Apr 2008 20:50:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1240</guid>
		<description>Well it&#039;s a matter of priorities.  You&#039;re concerns are valid, but I am more interested in the maintainability of the source.

Using something like JiBX (instrumentation) instead of Castor (refelction) makes the code cleaner because I don&#039;t have to compromise on encapsulation at coding time.  A developer can&#039;t call the instrumented code directly because its not there.  It doesn&#039;t exist until after compilation.  This means developers are less likely to (lazily or inadvertently) introduce inappropriate dependencies and coupling.

It&#039;s not a perfect solution for the reasons you point out, and I wouldn&#039;t use it for absolutely everything, but giving up on final fields and encapsulation (my definition of encapsulation rather than yours ;) ) is even less ideal in my opinion.

It can be tested but, just as for getters and setters that don&#039;t have their own tests, you&#039;d have to test it indirectly by testing the code that uses it.

The instrumentation approach also often comes with a big performance advantage over reflection-based techniques.</description>
		<content:encoded><![CDATA[<p>Well it&#8217;s a matter of priorities.  You&#8217;re concerns are valid, but I am more interested in the maintainability of the source.</p>
<p>Using something like JiBX (instrumentation) instead of Castor (refelction) makes the code cleaner because I don&#8217;t have to compromise on encapsulation at coding time.  A developer can&#8217;t call the instrumented code directly because its not there.  It doesn&#8217;t exist until after compilation.  This means developers are less likely to (lazily or inadvertently) introduce inappropriate dependencies and coupling.</p>
<p>It&#8217;s not a perfect solution for the reasons you point out, and I wouldn&#8217;t use it for absolutely everything, but giving up on final fields and encapsulation (my definition of encapsulation rather than yours <img src='http://blog.uncommons.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) is even less ideal in my opinion.</p>
<p>It can be tested but, just as for getters and setters that don&#8217;t have their own tests, you&#8217;d have to test it indirectly by testing the code that uses it.</p>
<p>The instrumentation approach also often comes with a big performance advantage over reflection-based techniques.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: name (required)</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1238</link>
		<dc:creator>name (required)</dc:creator>
		<pubDate>Wed, 09 Apr 2008 19:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1238</guid>
		<description>&quot;As for the Java Beans conventions (no-arg constructors and getters/setters). I’ve been thinking for a while that they are outdated. They made sense 10 years ago, but a lot of libraries have moved beyond the need for such clumsy conventions by using bytecode instrumentation to avoid having to compromise on encapsulation and invariants in your classes.&quot;

Oh, yeah, that&#039;s going to raise my confidence in my code. Code I can neither test nor read. Bytecode instrumentation IS breaking ALL encapsulation, by definition. Bytecode instrumentation is the universal pick to every encapsulation you thought you locked... a hacker&#039;s dream... a black hat&#039;s a-bomb. 

I mean, come on. Let&#039;s be rational.</description>
		<content:encoded><![CDATA[<p>&#8220;As for the Java Beans conventions (no-arg constructors and getters/setters). I’ve been thinking for a while that they are outdated. They made sense 10 years ago, but a lot of libraries have moved beyond the need for such clumsy conventions by using bytecode instrumentation to avoid having to compromise on encapsulation and invariants in your classes.&#8221;</p>
<p>Oh, yeah, that&#8217;s going to raise my confidence in my code. Code I can neither test nor read. Bytecode instrumentation IS breaking ALL encapsulation, by definition. Bytecode instrumentation is the universal pick to every encapsulation you thought you locked&#8230; a hacker&#8217;s dream&#8230; a black hat&#8217;s a-bomb. </p>
<p>I mean, come on. Let&#8217;s be rational.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Lawrey</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1199</link>
		<dc:creator>Peter Lawrey</dc:creator>
		<pubDate>Fri, 04 Apr 2008 19:12:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1199</guid>
		<description>If you cannot be bothered testing a method, you have to ask yourself whether you need it.
My suggestion is, don&#039;t add a getter/setter unless it actually is useful.  Don&#039;t forget you can have public final or public mutable fields and dump the extra code which doesn&#039;t add any value.
Certainly, 90%+ of getter/setter just bloat the code and the only real difference removing them would have is to make the code shorter.</description>
		<content:encoded><![CDATA[<p>If you cannot be bothered testing a method, you have to ask yourself whether you need it.<br />
My suggestion is, don&#8217;t add a getter/setter unless it actually is useful.  Don&#8217;t forget you can have public final or public mutable fields and dump the extra code which doesn&#8217;t add any value.<br />
Certainly, 90%+ of getter/setter just bloat the code and the only real difference removing them would have is to make the code shorter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Easter</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1186</link>
		<dc:creator>Michael Easter</dc:creator>
		<pubDate>Thu, 03 Apr 2008 01:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1186</guid>
		<description>I also agree with premise but have a different conclusion.  

Developers shouldn&#039;t test getters/setters: unit-test frameworks should (insofar as possible), via a configuration option or annotation.  It should be as easy as possible and, indeed, not given much merit as a metric.  

The unit-test frameworks (or code-coverage etc) should report on the number of getters/setters tested and the total number.  This posts asks &quot;do you have too many getters/setters?&quot;.  Good question: why not have the ability to report on it, in its own right?  Again, this is not a report for the CTO.

Finally, code-coverage should be able to report coverage percentages that either include or exclude getters and setters.  Then one would know the wheat from the chaff.</description>
		<content:encoded><![CDATA[<p>I also agree with premise but have a different conclusion.  </p>
<p>Developers shouldn&#8217;t test getters/setters: unit-test frameworks should (insofar as possible), via a configuration option or annotation.  It should be as easy as possible and, indeed, not given much merit as a metric.  </p>
<p>The unit-test frameworks (or code-coverage etc) should report on the number of getters/setters tested and the total number.  This posts asks &#8220;do you have too many getters/setters?&#8221;.  Good question: why not have the ability to report on it, in its own right?  Again, this is not a report for the CTO.</p>
<p>Finally, code-coverage should be able to report coverage percentages that either include or exclude getters and setters.  Then one would know the wheat from the chaff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1185</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 02 Apr 2008 20:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1185</guid>
		<description>Fabrizio, good points.  The 75% figure was plucked out of the air (it just happens to be the figure mentioned in the post I linked to).  My point is not to just aim for a particular figure (whether 75% or 95%) because it&#039;s too easy to fall into the trap of chasing the numbers rather than adding value.

You are right about Swing.  Even without the getters and setters, UI code is hard to test well.  Using something like FEST (http://fest.easytesting.org/swing/wiki/pmwiki.php) gets you some of the way there but I&#039;m never really satisifed with my UI tests.

As for the Java Beans conventions (no-arg constructors and getters/setters).  I&#039;ve been thinking for a while that they are outdated.  They made sense 10 years ago, but a lot of libraries have moved beyond the need for such clumsy conventions by using bytecode instrumentation to avoid having to compromise on encapsulation and invariants in your classes.</description>
		<content:encoded><![CDATA[<p>Fabrizio, good points.  The 75% figure was plucked out of the air (it just happens to be the figure mentioned in the post I linked to).  My point is not to just aim for a particular figure (whether 75% or 95%) because it&#8217;s too easy to fall into the trap of chasing the numbers rather than adding value.</p>
<p>You are right about Swing.  Even without the getters and setters, UI code is hard to test well.  Using something like FEST (<a href="http://fest.easytesting.org/swing/wiki/pmwiki.php" rel="nofollow">http://fest.easytesting.org/swing/wiki/pmwiki.php</a>) gets you some of the way there but I&#8217;m never really satisifed with my UI tests.</p>
<p>As for the Java Beans conventions (no-arg constructors and getters/setters).  I&#8217;ve been thinking for a while that they are outdated.  They made sense 10 years ago, but a lot of libraries have moved beyond the need for such clumsy conventions by using bytecode instrumentation to avoid having to compromise on encapsulation and invariants in your classes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabrizio Giudici</title>
		<link>http://blog.uncommons.org/2008/04/01/getters-setters-and-the-great-coverage-conspiracy/comment-page-1/#comment-1184</link>
		<dc:creator>Fabrizio Giudici</dc:creator>
		<pubDate>Wed, 02 Apr 2008 20:32:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.uncommons.org/?p=65#comment-1184</guid>
		<description>I agree with most of the premises, but I draw a slightly different conclusion. Right because of what you said about the 75% coverage, I think that the actual coverage should be around 90%-95% (on the other hand I&#039;m not so strict about the fact that the coverage is only achieved by unit tests, a mix of unit and integration tests would do as well).

Now, covering getters and setters becomes important so you don&#039; run into the opposite mistake: ah, well, there&#039;s a 25% missing coverage, but it&#039;s getters and setters, while maybe the lack of coverage is in another place. This could be addressed in a different way if we had an annotation such as @IgnoreCoverage that prevents coverage tools to take some method into account, but somebody could misuse that.

At last, you&#039;re right about having too many getters and setters, but here the problem is with specific technologies: e.g. if you have JavaBeans based stuff (which is a huge set of things, from Swing to JSF to JPA) you need to have a good number of getters and setters (and for Swing this means that you need also property change listeners, which indeed is a good thing to test).</description>
		<content:encoded><![CDATA[<p>I agree with most of the premises, but I draw a slightly different conclusion. Right because of what you said about the 75% coverage, I think that the actual coverage should be around 90%-95% (on the other hand I&#8217;m not so strict about the fact that the coverage is only achieved by unit tests, a mix of unit and integration tests would do as well).</p>
<p>Now, covering getters and setters becomes important so you don&#8217; run into the opposite mistake: ah, well, there&#8217;s a 25% missing coverage, but it&#8217;s getters and setters, while maybe the lack of coverage is in another place. This could be addressed in a different way if we had an annotation such as @IgnoreCoverage that prevents coverage tools to take some method into account, but somebody could misuse that.</p>
<p>At last, you&#8217;re right about having too many getters and setters, but here the problem is with specific technologies: e.g. if you have JavaBeans based stuff (which is a huge set of things, from Swing to JSF to JPA) you need to have a good number of getters and setters (and for Swing this means that you need also property change listeners, which indeed is a good thing to test).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.264 seconds -->
