<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Testing antipatterns</title>
	<atom:link href="http://schneide.wordpress.com/2012/08/07/testing-antipatterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/</link>
	<description>public business secrets</description>
	<lastBuildDate>Tue, 14 May 2013 22:01:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: JavaPins</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6412</link>
		<dc:creator><![CDATA[JavaPins]]></dc:creator>
		<pubDate>Sat, 11 Aug 2012 14:17:36 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6412</guid>
		<description><![CDATA[&lt;strong&gt;Testing antipatterns...&lt;/strong&gt;

Thank you for submitting this cool story - Trackback from JavaPins...]]></description>
		<content:encoded><![CDATA[<p><strong>Testing antipatterns&#8230;</strong></p>
<p>Thank you for submitting this cool story &#8211; Trackback from JavaPins&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jenslukowski</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6396</link>
		<dc:creator><![CDATA[jenslukowski]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 14:16:49 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6396</guid>
		<description><![CDATA[Yes, we use Joda Time for our projects since it handles many things much better than the built in Date/Calendar libs. The above code is just used Date as an example to not complicate it.
I agree with you that immutable objects are the way to go, it&#039;s one of the things which I find very interesting in languages like Clojure which have builtin immutable or value objects. I&#039;ve read Effective Java but yes, I should re-read it and should adhere more to the rules in there. Immutable objects make using them easier especially in multithreaded environments. Maybe you&#039;ve read it already but I found John Carmack&#039;s approach to using functional programming parts very pragmatic and helpful: http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/]]></description>
		<content:encoded><![CDATA[<p>Yes, we use Joda Time for our projects since it handles many things much better than the built in Date/Calendar libs. The above code is just used Date as an example to not complicate it.<br />
I agree with you that immutable objects are the way to go, it&#8217;s one of the things which I find very interesting in languages like Clojure which have builtin immutable or value objects. I&#8217;ve read Effective Java but yes, I should re-read it and should adhere more to the rules in there. Immutable objects make using them easier especially in multithreaded environments. Maybe you&#8217;ve read it already but I found John Carmack&#8217;s approach to using functional programming parts very pragmatic and helpful: <a href="http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/" rel="nofollow">http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Jablow</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6395</link>
		<dc:creator><![CDATA[Eric Jablow]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 14:01:48 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6395</guid>
		<description><![CDATA[Ye. It&#039;s one of the rules from &quot;Effective Java&quot;.  Classes with mutable instance variables should copy them both on input and on output. Otherwise a malicious programmer could break your objects.  Suppose DtaeRange had vanilla getters and setters. Consider code like

Date today = new Date();
Date tomorrow = ...; // code omitted.
DateRange range = new DateRange(today, tomorrow);
// Assume DateRange checks that start is before end.
today.setTime(aLongRepresentingNextYear);
//Since DateRange did not copy start,
// range.start is now after range.end.

As Effective Java said, don&#039;t use clone() to copy the dates on input either.  Somebody might give a preverse subclass of Date. In fact try to read and memorize that book.

Best is to use immutable objects as much as possible. Use the Joda-Time library instead of java.util.Date, for example. Use the offical replacement Date library when Java 8 or 9 eventually adds it]]></description>
		<content:encoded><![CDATA[<p>Ye. It&#8217;s one of the rules from &#8220;Effective Java&#8221;.  Classes with mutable instance variables should copy them both on input and on output. Otherwise a malicious programmer could break your objects.  Suppose DtaeRange had vanilla getters and setters. Consider code like</p>
<p>Date today = new Date();<br />
Date tomorrow = &#8230;; // code omitted.<br />
DateRange range = new DateRange(today, tomorrow);<br />
// Assume DateRange checks that start is before end.<br />
today.setTime(aLongRepresentingNextYear);<br />
//Since DateRange did not copy start,<br />
// range.start is now after range.end.</p>
<p>As Effective Java said, don&#8217;t use clone() to copy the dates on input either.  Somebody might give a preverse subclass of Date. In fact try to read and memorize that book.</p>
<p>Best is to use immutable objects as much as possible. Use the Joda-Time library instead of java.util.Date, for example. Use the offical replacement Date library when Java 8 or 9 eventually adds it</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rogerio</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6394</link>
		<dc:creator><![CDATA[Rogerio]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 13:11:05 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6394</guid>
		<description><![CDATA[I am not sure about always using a message for each assertion...

In practice, it is hardly useful because you still need to open the test method in your IDE, run it to confirm the failure, apply a fix, then run the test again to confirm it now passes. Just reading the error message (plus the test name) is usually not enough to understand what the test is about or why it failed. You actually need to look at the test as a whole to achieve that, and having that message or not will often not make any real difference. Not to mention that such messages can easily be poorly written or misleading. At least, this has been my experience.]]></description>
		<content:encoded><![CDATA[<p>I am not sure about always using a message for each assertion&#8230;</p>
<p>In practice, it is hardly useful because you still need to open the test method in your IDE, run it to confirm the failure, apply a fix, then run the test again to confirm it now passes. Just reading the error message (plus the test name) is usually not enough to understand what the test is about or why it failed. You actually need to look at the test as a whole to achieve that, and having that message or not will often not make any real difference. Not to mention that such messages can easily be poorly written or misleading. At least, this has been my experience.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jenslukowski</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6391</link>
		<dc:creator><![CDATA[jenslukowski]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 09:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6391</guid>
		<description><![CDATA[If I understand you correctly, you mean that a setter should make a copy of its passed value and the test should test for this. That&#039;s another good aspect. Thank you]]></description>
		<content:encoded><![CDATA[<p>If I understand you correctly, you mean that a setter should make a copy of its passed value and the test should test for this. That&#8217;s another good aspect. Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jenslukowski</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6390</link>
		<dc:creator><![CDATA[jenslukowski]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 09:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6390</guid>
		<description><![CDATA[Yes, thank you.
The patterns where extracted from (old) JUnit3 tests, so the solution could be made even better when using JUnit4.]]></description>
		<content:encoded><![CDATA[<p>Yes, thank you.<br />
The patterns where extracted from (old) JUnit3 tests, so the solution could be made even better when using JUnit4.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jenslukowski</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6389</link>
		<dc:creator><![CDATA[jenslukowski]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 09:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6389</guid>
		<description><![CDATA[Yep]]></description>
		<content:encoded><![CDATA[<p>Yep</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jenslukowski</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6388</link>
		<dc:creator><![CDATA[jenslukowski]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 09:09:56 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6388</guid>
		<description><![CDATA[You are right, thank you, missed out on that one, Updated the post accordingly.]]></description>
		<content:encoded><![CDATA[<p>You are right, thank you, missed out on that one, Updated the post accordingly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6385</link>
		<dc:creator><![CDATA[Mike]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 02:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6385</guid>
		<description><![CDATA[So... in summary: Always use a message. Enable assertions. Don&#039;t have multiple code paths in a test.]]></description>
		<content:encoded><![CDATA[<p>So&#8230; in summary: Always use a message. Enable assertions. Don&#8217;t have multiple code paths in a test.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars Briem</title>
		<link>http://schneide.wordpress.com/2012/08/07/testing-antipatterns/#comment-6381</link>
		<dc:creator><![CDATA[Lars Briem]]></dc:creator>
		<pubDate>Wed, 08 Aug 2012 20:15:25 +0000</pubDate>
		<guid isPermaLink="false">http://schneide.wordpress.com/?p=3699#comment-6381</guid>
		<description><![CDATA[Thanks for this nice article on some antipatterns of unit tests, but I think there are two little mistakes in the last solution of the exception example:

try {
  callFailingMethod()
} catch (ParseException e) {
  fail(&quot;Invalid character at line 2&quot;, e.getMessage())
}

The first one is, that you use the &quot;fail&quot; method to compare the two messages. I think this should be an &quot;asserEquals&quot; call, shouldn&#039;t it?
So I think it should be like this:

try {
  callFailingMethod()
} catch (ParseException e) {
  assertEquals(&quot;Invalid character at line 2&quot;, e.getMessage())
}


The other one is, a bit difficult because I do not know if I understand the code correct. 
In my opinion you want to test that the &quot;callFailingMethod&quot; throws an exception. But your test will also pass if no exception is thrown. For this case the &quot;fail&quot; call after the &quot;callFailingMethod&quot; is necessary and can not be removed.
So my final solution looks like this:

try {
  callFailingMethod()
  fail(&quot;ParseException should be thrown.&quot;)
} catch (ParseException e) {
  assertEquals(&quot;Invalid character at line 2&quot;, e.getMessage())
}

Am I right or do I miss something?]]></description>
		<content:encoded><![CDATA[<p>Thanks for this nice article on some antipatterns of unit tests, but I think there are two little mistakes in the last solution of the exception example:</p>
<p>try {<br />
  callFailingMethod()<br />
} catch (ParseException e) {<br />
  fail(&#8220;Invalid character at line 2&#8243;, e.getMessage())<br />
}</p>
<p>The first one is, that you use the &#8220;fail&#8221; method to compare the two messages. I think this should be an &#8220;asserEquals&#8221; call, shouldn&#8217;t it?<br />
So I think it should be like this:</p>
<p>try {<br />
  callFailingMethod()<br />
} catch (ParseException e) {<br />
  assertEquals(&#8220;Invalid character at line 2&#8243;, e.getMessage())<br />
}</p>
<p>The other one is, a bit difficult because I do not know if I understand the code correct.<br />
In my opinion you want to test that the &#8220;callFailingMethod&#8221; throws an exception. But your test will also pass if no exception is thrown. For this case the &#8220;fail&#8221; call after the &#8220;callFailingMethod&#8221; is necessary and can not be removed.<br />
So my final solution looks like this:</p>
<p>try {<br />
  callFailingMethod()<br />
  fail(&#8220;ParseException should be thrown.&#8221;)<br />
} catch (ParseException e) {<br />
  assertEquals(&#8220;Invalid character at line 2&#8243;, e.getMessage())<br />
}</p>
<p>Am I right or do I miss something?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
