<?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: The Testing Anti-Patterns Drafts Vol. 1</title>
	<atom:link href="http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/</link>
	<description>nutrun</description>
	<pubDate>Tue, 06 Jan 2009 05:49:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: George Malamidis</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-204</link>
		<dc:creator>George Malamidis</dc:creator>
		<pubDate>Tue, 14 Nov 2006 23:20:35 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-204</guid>
		<description>Matt,

The assertion is made on the value of the private field being the one expected after the method under test has been invoked. If the value is not what it's expected to be, the test will break as it should. If a field with that name is no longer there, the test will break. As is should.
I would suggest there is no such thing as a 'fragile test'. Tests are meant to break when the behavior they describe is not met.

In terms of good and bad practices:

When you want to test the value of a private field, you have three options:

- Expose a public getter on it or bend your application code to accommodate access, thus breaking encapsulation.

- Not test it, thus leaving a window for a potential bug to creep in.

- Reflect and assert on it.

To everyone who gets phased by reflection:

If you've ever used Spring, WebWork, Hibernate, JMock (... and the list goes on and on, way beyond Java frameworks), I've got bad news for you: Your applications are 'fragile', because most frameworks out there use reflection all over the place.

Just because reflection is dangerous in the hands of inexperienced developers, as are most powerful techniques, it doesn't mean it's bad. Fire burns, but there's a million useful things you can do with it if you know how.

Don't buy the reflection FUD just because somebody told you they got burned by it. Learn how to use it properly instead.</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>The assertion is made on the value of the private field being the one expected after the method under test has been invoked. If the value is not what it&#8217;s expected to be, the test will break as it should. If a field with that name is no longer there, the test will break. As is should.<br />
I would suggest there is no such thing as a &#8216;fragile test&#8217;. Tests are meant to break when the behavior they describe is not met.</p>
<p>In terms of good and bad practices:</p>
<p>When you want to test the value of a private field, you have three options:</p>
<p>- Expose a public getter on it or bend your application code to accommodate access, thus breaking encapsulation.</p>
<p>- Not test it, thus leaving a window for a potential bug to creep in.</p>
<p>- Reflect and assert on it.</p>
<p>To everyone who gets phased by reflection:</p>
<p>If you&#8217;ve ever used Spring, WebWork, Hibernate, JMock (&#8230; and the list goes on and on, way beyond Java frameworks), I&#8217;ve got bad news for you: Your applications are &#8216;fragile&#8217;, because most frameworks out there use reflection all over the place.</p>
<p>Just because reflection is dangerous in the hands of inexperienced developers, as are most powerful techniques, it doesn&#8217;t mean it&#8217;s bad. Fire burns, but there&#8217;s a million useful things you can do with it if you know how.</p>
<p>Don&#8217;t buy the reflection FUD just because somebody told you they got burned by it. Learn how to use it properly instead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt deiters</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-203</link>
		<dc:creator>matt deiters</dc:creator>
		<pubDate>Tue, 14 Nov 2006 21:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-203</guid>
		<description>+1 To Damiens Comment - Using reflection to test protected/private memebers is going to product very fragile tests...It is easier to describe good practices and bad practices when you create a real test in your example - What are you trying to test?</description>
		<content:encoded><![CDATA[<p>+1 To Damiens Comment - Using reflection to test protected/private memebers is going to product very fragile tests&#8230;It is easier to describe good practices and bad practices when you create a real test in your example - What are you trying to test?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Ingles</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-202</link>
		<dc:creator>Paul Ingles</dc:creator>
		<pubDate>Fri, 29 Sep 2006 19:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-202</guid>
		<description>The issue of what constitutes equality between objects is fundamental to OO design. I just don't see how it's something that should be avoided.

Admitted, in a unit test on the object I may want to test that when I say a.equals(b) that the equality is determined by a set of _particular_ fields.

I completely agree with you when you say 'Equality is an integral attribute of a Class’s behavior and should be strictly meaningful under the context of the Class’s definition.', but, I'm not sure I see why tests that assertEquals are wrong, if indeed you are trying to assert an object's equality. Your tests are revealing your intention for the code, and there's just no getting around the fact your looking for equality.</description>
		<content:encoded><![CDATA[<p>The issue of what constitutes equality between objects is fundamental to OO design. I just don&#8217;t see how it&#8217;s something that should be avoided.</p>
<p>Admitted, in a unit test on the object I may want to test that when I say a.equals(b) that the equality is determined by a set of _particular_ fields.</p>
<p>I completely agree with you when you say &#8216;Equality is an integral attribute of a Class’s behavior and should be strictly meaningful under the context of the Class’s definition.&#8217;, but, I&#8217;m not sure I see why tests that assertEquals are wrong, if indeed you are trying to assert an object&#8217;s equality. Your tests are revealing your intention for the code, and there&#8217;s just no getting around the fact your looking for equality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-201</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Sun, 24 Sep 2006 23:33:26 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-201</guid>
		<description>I agree with Damian Guy.

Through interfaces (or even those crazy superclass things), one object can have many public members, but they aren't accessible everywhere (without crazy casting).

So if you have ComplexObject, an interface, you could have your implementation expose the fields, and only have your automated tests call the implementation directly.

A further problem is 'exhausting testing'.  I don't mean 'exhaustive testing'.  It's impossible to write complete (exhaustive) tests for most code.  You end up testing some things, not quite at random, but often just according to what's easiest to test.

In fact, you can end up just duplicating the 'real' code.  I'd suggest instead to make sure that the tests exercise code that is used by users, i.e., don't write tests that test things that can't happen in a live environment.

That doesn't mean you shouldn't write tests that probe behaviour under strange situations, but you shouldn't bother doing that if those strange situations can be filtered out instead.  Instead of *exhausting* yourself trying to write exhaustive tests, write better application code.</description>
		<content:encoded><![CDATA[<p>I agree with Damian Guy.</p>
<p>Through interfaces (or even those crazy superclass things), one object can have many public members, but they aren&#8217;t accessible everywhere (without crazy casting).</p>
<p>So if you have ComplexObject, an interface, you could have your implementation expose the fields, and only have your automated tests call the implementation directly.</p>
<p>A further problem is &#8216;exhausting testing&#8217;.  I don&#8217;t mean &#8216;exhaustive testing&#8217;.  It&#8217;s impossible to write complete (exhaustive) tests for most code.  You end up testing some things, not quite at random, but often just according to what&#8217;s easiest to test.</p>
<p>In fact, you can end up just duplicating the &#8216;real&#8217; code.  I&#8217;d suggest instead to make sure that the tests exercise code that is used by users, i.e., don&#8217;t write tests that test things that can&#8217;t happen in a live environment.</p>
<p>That doesn&#8217;t mean you shouldn&#8217;t write tests that probe behaviour under strange situations, but you shouldn&#8217;t bother doing that if those strange situations can be filtered out instead.  Instead of *exhausting* yourself trying to write exhaustive tests, write better application code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhanji</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-200</link>
		<dc:creator>Dhanji</dc:creator>
		<pubDate>Sun, 24 Sep 2006 23:25:56 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-200</guid>
		<description>&#38;gt;Alex mentioned Hibernate in his blog entry but that’s only because Hibernate is forcing your object’s equals definition to be an entity equals instead of a values equals.

&#38;gt;I’m thinking more that Java should have Object.equals() and Object.same()

It is not just Hibernate that requires this behavior, the JCF does too, which is integral to java. Java already has == for references, equals is meant to test semantic equivalence. What could same() possibly test for? If you wanted different levels of equality, then declare your own.

btw, Junit-objects offers reflective assertion via expressions on beans:

http://junit-objects.sourceforge.net</description>
		<content:encoded><![CDATA[<p>&#38;gt;Alex mentioned Hibernate in his blog entry but that’s only because Hibernate is forcing your object’s equals definition to be an entity equals instead of a values equals.</p>
<p>&#38;gt;I’m thinking more that Java should have Object.equals() and Object.same()</p>
<p>It is not just Hibernate that requires this behavior, the JCF does too, which is integral to java. Java already has == for references, equals is meant to test semantic equivalence. What could same() possibly test for? If you wanted different levels of equality, then declare your own.</p>
<p>btw, Junit-objects offers reflective assertion via expressions on beans:</p>
<p><a href="http://junit-objects.sourceforge.net" rel="nofollow">http://junit-objects.sourceforge.net</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Arnold</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-199</link>
		<dc:creator>Jim Arnold</dc:creator>
		<pubDate>Sun, 24 Sep 2006 22:32:22 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-199</guid>
		<description>I'm pretty sure I agree with Damian - there's little difference between a public field and a private one accessed via reflection.  It may well be that coupling the tests so tightly to their class in this way leads to a better design, but I am not convinced.

Jim</description>
		<content:encoded><![CDATA[<p>I&#8217;m pretty sure I agree with Damian - there&#8217;s little difference between a public field and a private one accessed via reflection.  It may well be that coupling the tests so tightly to their class in this way leads to a better design, but I am not convinced.</p>
<p>Jim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alistair Jones</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-198</link>
		<dc:creator>Alistair Jones</dc:creator>
		<pubDate>Sun, 24 Sep 2006 15:34:12 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-198</guid>
		<description>Slightly off-topic, but if I need a class like ObjectMother, I prefer to name the methods "make..." or "create.." rather than "get...".  The get prefix is heavily overused and most people  expect the semantics to be that I call getComplexObject() twice in a row I'll get the same object, which probably isn't true in this case.</description>
		<content:encoded><![CDATA[<p>Slightly off-topic, but if I need a class like ObjectMother, I prefer to name the methods &#8220;make&#8230;&#8221; or &#8220;create..&#8221; rather than &#8220;get&#8230;&#8221;.  The get prefix is heavily overused and most people  expect the semantics to be that I call getComplexObject() twice in a row I&#8217;ll get the same object, which probably isn&#8217;t true in this case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damian Guy</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-197</link>
		<dc:creator>Damian Guy</dc:creator>
		<pubDate>Sun, 24 Sep 2006 10:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-197</guid>
		<description>Using reflection to assert equality etc of fields private to the class under test is itself an anti-pattern! Test drive the public api and don't expose the guts of a class, even if you are using reflection to do it.</description>
		<content:encoded><![CDATA[<p>Using reflection to assert equality etc of fields private to the class under test is itself an anti-pattern! Test drive the public api and don&#8217;t expose the guts of a class, even if you are using reflection to do it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Yip</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-196</link>
		<dc:creator>Jason Yip</dc:creator>
		<pubDate>Sun, 24 Sep 2006 00:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-196</guid>
		<description>I think the underlying design problem is "Complex Object".

What is a specific example of a reasonably scoped Class that should not have equals/hashCode behaviour based on values?

Alex mentioned Hibernate in his blog entry but that's only because Hibernate is forcing your object's equals definition to be an entity equals instead of a values equals.

I'm thinking more that Java should have Object.equals() and Object.same()</description>
		<content:encoded><![CDATA[<p>I think the underlying design problem is &#8220;Complex Object&#8221;.</p>
<p>What is a specific example of a reasonably scoped Class that should not have equals/hashCode behaviour based on values?</p>
<p>Alex mentioned Hibernate in his blog entry but that&#8217;s only because Hibernate is forcing your object&#8217;s equals definition to be an entity equals instead of a values equals.</p>
<p>I&#8217;m thinking more that Java should have Object.equals() and Object.same()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Ruiz</title>
		<link>http://nutrun.com/weblog/the-testing-anti-patterns-drafts-vol-1/comment-page-1/#comment-195</link>
		<dc:creator>Alex Ruiz</dc:creator>
		<pubDate>Sat, 23 Sep 2006 18:32:44 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=53#comment-195</guid>
		<description>Hi George,

I read your post and totally agree. I always had this doubt about equals/hashCode and object behavior. Thanks a lot!!

I added some comments at my blog: http://www.jroller.com/page/alexRuiz?entry=don_t_break_oo_in

Best regards,
Alex.</description>
		<content:encoded><![CDATA[<p>Hi George,</p>
<p>I read your post and totally agree. I always had this doubt about equals/hashCode and object behavior. Thanks a lot!!</p>
<p>I added some comments at my blog: <a href="http://www.jroller.com/page/alexRuiz?entry=don_t_break_oo_in" rel="nofollow">http://www.jroller.com/page/alexRuiz?entry=don_t_break_oo_in</a></p>
<p>Best regards,<br />
Alex.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
