<?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: How to Write Good Unit Tests</title>
	<atom:link href="http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests</link>
	<description></description>
	<lastBuildDate>Fri, 12 Mar 2010 03:55:20 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Why is automated unit testing important? &#171; Ryan Eastabrook</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-104354</link>
		<dc:creator>Why is automated unit testing important? &#171; Ryan Eastabrook</dc:creator>
		<pubDate>Wed, 17 Feb 2010 04:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-104354</guid>
		<description>[...] (Java): http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests      Categories: Uncategorized        Comments (0) Trackbacks (0) Leave a comment [...]</description>
		<content:encoded><![CDATA[<p>[...] (Java): <a href="http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests" rel="nofollow">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests</a>      Categories: Uncategorized        Comments (0) Trackbacks (0) Leave a comment [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Basil Vandegriend</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-97714</link>
		<dc:creator>Basil Vandegriend</dc:creator>
		<pubDate>Sat, 26 Sep 2009 02:36:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-97714</guid>
		<description>@tinca, I often do write tests for a method based on its contract (preconditions &amp; postconditions). However, I seldom test for the negative case (e.g. that the method fails with an exception if a precondition is violated). Instead, I focus on testing that the method behaves properly when the preconditions are met. E.g. if an argument can be null, then I verify that the method accepts a null as well as a non-null value.</description>
		<content:encoded><![CDATA[<p>@tinca, I often do write tests for a method based on its contract (preconditions &#038; postconditions). However, I seldom test for the negative case (e.g. that the method fails with an exception if a precondition is violated). Instead, I focus on testing that the method behaves properly when the preconditions are met. E.g. if an argument can be null, then I verify that the method accepts a null as well as a non-null value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tinca</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-97683</link>
		<dc:creator>tinca</dc:creator>
		<pubDate>Fri, 25 Sep 2009 05:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-97683</guid>
		<description>Would you write cases that test contracts? For instance: when null is passed IllegalArgumentException must be thrown? It may seem a trivial one, but on the long run it can protect again accidental changes.</description>
		<content:encoded><![CDATA[<p>Would you write cases that test contracts? For instance: when null is passed IllegalArgumentException must be thrown? It may seem a trivial one, but on the long run it can protect again accidental changes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Basil Vandegriend</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-79305</link>
		<dc:creator>Basil Vandegriend</dc:creator>
		<pubDate>Sat, 07 Feb 2009 14:00:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-79305</guid>
		<description>@Rick, there are a few guidelines I can provide about when the code is not trivial. The two solid examples I provided in the article where getter &amp; setter methods with no logic and simple constructors (that just populate fields from parameters passed in). Another example would be delegate methods that simnply delegate execution to another class. I.e.
private Bar delegate;

public void doStuff(Foo foo) {
  delegate.doStuff(foo);
}

The general principle is this: how confident are you that the code is correct? If you are 100% confident, then this is trivial code that you do not need to test. If you have doubts or uncertainties, then you should write a test.</description>
		<content:encoded><![CDATA[<p>@Rick, there are a few guidelines I can provide about when the code is not trivial. The two solid examples I provided in the article where getter &#038; setter methods with no logic and simple constructors (that just populate fields from parameters passed in). Another example would be delegate methods that simnply delegate execution to another class. I.e.<br />
private Bar delegate;</p>
<p>public void doStuff(Foo foo) {<br />
  delegate.doStuff(foo);<br />
}</p>
<p>The general principle is this: how confident are you that the code is correct? If you are 100% confident, then this is trivial code that you do not need to test. If you have doubts or uncertainties, then you should write a test.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Pingry</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-79107</link>
		<dc:creator>Rick Pingry</dc:creator>
		<pubDate>Fri, 06 Feb 2009 23:58:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-79107</guid>
		<description>I would like to know more about writing tests for trivial code.  When is the code NOT trivial?  Where is the line between trivial code and non-trivial code?  Can anyone provide some solid examples?</description>
		<content:encoded><![CDATA[<p>I would like to know more about writing tests for trivial code.  When is the code NOT trivial?  Where is the line between trivial code and non-trivial code?  Can anyone provide some solid examples?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Basil Vandegriend</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-71972</link>
		<dc:creator>Basil Vandegriend</dc:creator>
		<pubDate>Wed, 07 Jan 2009 01:46:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-71972</guid>
		<description>@Deepak, thanks for your comment. The article does provide guidance on how to transform the &#039;what-not-to-do&#039; examples into better tests. I explicitly wrote the article this way to provide some concrete guidance to people to write better tests, but you are right that I do not provide instructions on the basics of writing a good test case. I am tentatively planning to write some more articles on unit testing in the near future, so stay tuned.</description>
		<content:encoded><![CDATA[<p>@Deepak, thanks for your comment. The article does provide guidance on how to transform the &#8216;what-not-to-do&#8217; examples into better tests. I explicitly wrote the article this way to provide some concrete guidance to people to write better tests, but you are right that I do not provide instructions on the basics of writing a good test case. I am tentatively planning to write some more articles on unit testing in the near future, so stay tuned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepak</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-71954</link>
		<dc:creator>Deepak</dc:creator>
		<pubDate>Tue, 06 Jan 2009 12:13:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-71954</guid>
		<description>Information provided is useful to some extent, but it would be helpful if you clearly specify how to write good junit test cases with examples. Right now you have explained what not to do.</description>
		<content:encoded><![CDATA[<p>Information provided is useful to some extent, but it would be helpful if you clearly specify how to write good junit test cases with examples. Right now you have explained what not to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-21700</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Fri, 22 Jun 2007 08:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-21700</guid>
		<description>Read about private field/method accessor. There is a possibility in Java to change visibility and use private methods and fields.

import java.lang.reflect.Field;
import junit.framework.Assert;

/**
 * Provides access to private members in the application classes.
 */
public class PrivateFieldAccessor {
	
  public static Object getPrivateField (Object o, String fieldName) {
    
	  /* Check we have valid arguments */
	  Assert.assertNotNull(o);
	  Assert.assertNotNull(fieldName);
    
	  /* Go and find the private field... */
    final Field fields[] = o.getClass().getDeclaredFields();
    
    for (int i = 0; i </description>
		<content:encoded><![CDATA[<p>Read about private field/method accessor. There is a possibility in Java to change visibility and use private methods and fields.</p>
<p>import java.lang.reflect.Field;<br />
import junit.framework.Assert;</p>
<p>/**<br />
 * Provides access to private members in the application classes.<br />
 */<br />
public class PrivateFieldAccessor {</p>
<p>  public static Object getPrivateField (Object o, String fieldName) {</p>
<p>	  /* Check we have valid arguments */<br />
	  Assert.assertNotNull(o);<br />
	  Assert.assertNotNull(fieldName);</p>
<p>	  /* Go and find the private field&#8230; */<br />
    final Field fields[] = o.getClass().getDeclaredFields();</p>
<p>    for (int i = 0; i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Worth Reading &#187; Skillful Software</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-16665</link>
		<dc:creator>Worth Reading &#187; Skillful Software</dc:creator>
		<pubDate>Mon, 28 May 2007 12:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-16665</guid>
		<description>[...] year, Basil Vandegriend put out a concise and helpful post on writing good unit tests. Most people agree tests are important, but many do not know precisely how to make them work. Basil [...]</description>
		<content:encoded><![CDATA[<p>[...] year, Basil Vandegriend put out a concise and helpful post on writing good unit tests. Most people agree tests are important, but many do not know precisely how to make them work. Basil [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Basil Vandegriend</title>
		<link>http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests/comment-page-1#comment-853</link>
		<dc:creator>Basil Vandegriend</dc:creator>
		<pubDate>Wed, 27 Sep 2006 03:04:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/how-to-write-good-unit-tests#comment-853</guid>
		<description>I sometimes test private methods if they have non-trivial logic. To test them, I change them from private to package (default) access so that my test class in the same package can access them. I usually add a comment above the method to indicate that it is non-private in order to test it.</description>
		<content:encoded><![CDATA[<p>I sometimes test private methods if they have non-trivial logic. To test them, I change them from private to package (default) access so that my test class in the same package can access them. I usually add a comment above the method to indicate that it is non-private in order to test it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
