<?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: Unit Testing Isolated Methods with Groovy</title>
	<atom:link href="http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/</link>
	<description>Groovy, Grails and OS X tips and tricks</description>
	<lastBuildDate>Thu, 17 May 2012 00:35:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Ben</title>
		<link>http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/comment-page-1/#comment-2960</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 01 Feb 2011 16:45:28 +0000</pubDate>
		<guid isPermaLink="false">http://tednaleid.wordpress.com/?p=9#comment-2960</guid>
		<description>Just a note you should add a try/catch/finally block around closure.call to ensure that the metaClass is removed if an invoked method throws an exception.  Otherwise this works great, many thanks!!

try{
  closure.call() // call the code that tests methodRef in isolation
}
finally{ 
        GroovySystem.metaClassRegistry.removeMetaClass(clazz) // clean up after ourselves
}</description>
		<content:encoded><![CDATA[<p>Just a note you should add a try/catch/finally block around closure.call to ensure that the metaClass is removed if an invoked method throws an exception.  Otherwise this works great, many thanks!!</p>
<p>try{<br />
  closure.call() // call the code that tests methodRef in isolation<br />
}<br />
finally{<br />
        GroovySystem.metaClassRegistry.removeMetaClass(clazz) // clean up after ourselves<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ewan Dawson</title>
		<link>http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/comment-page-1/#comment-2606</link>
		<dc:creator>Ewan Dawson</dc:creator>
		<pubDate>Thu, 25 Mar 2010 09:40:20 +0000</pubDate>
		<guid isPermaLink="false">http://tednaleid.wordpress.com/?p=9#comment-2606</guid>
		<description>Great example.  Metaprogramming really makes testing a whole lot easier.</description>
		<content:encoded><![CDATA[<p>Great example.  Metaprogramming really makes testing a whole lot easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tednaleid</title>
		<link>http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/comment-page-1/#comment-10</link>
		<dc:creator>tednaleid</dc:creator>
		<pubDate>Tue, 01 Apr 2008 03:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://tednaleid.wordpress.com/?p=9#comment-10</guid>
		<description>Hamlet, thanks for your response!

I&#039;ve only ever used the interface mocking abilities of EasyMock and haven&#039;t tried it with the class extensions.  From a brief look, it appears that using the class extensions to create a partial mock is pretty similar to what I&#039;m doing above.  It&#039;s pulling a reference to the method under test and mocking out the rest of the class.

The Test-Specific Subclass pattern is another good alternative.  Though it sounds like it might be a bit of work to create a new subclass and maintain the additional instrumentation on the subclass that exposes and controls the state for testing.

I could definitely see that pattern being useful when working with legacy code that you don&#039;t have much control over.</description>
		<content:encoded><![CDATA[<p>Hamlet, thanks for your response!</p>
<p>I&#8217;ve only ever used the interface mocking abilities of EasyMock and haven&#8217;t tried it with the class extensions.  From a brief look, it appears that using the class extensions to create a partial mock is pretty similar to what I&#8217;m doing above.  It&#8217;s pulling a reference to the method under test and mocking out the rest of the class.</p>
<p>The Test-Specific Subclass pattern is another good alternative.  Though it sounds like it might be a bit of work to create a new subclass and maintain the additional instrumentation on the subclass that exposes and controls the state for testing.</p>
<p>I could definitely see that pattern being useful when working with legacy code that you don&#8217;t have much control over.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hamlet D'Arcy</title>
		<link>http://naleid.com/blog/2008/03/24/unit-testing-isolated-methods-with-groovy/comment-page-1/#comment-9</link>
		<dc:creator>Hamlet D'Arcy</dc:creator>
		<pubDate>Sun, 30 Mar 2008 11:49:42 +0000</pubDate>
		<guid isPermaLink="false">http://tednaleid.wordpress.com/?p=9#comment-9</guid>
		<description>Very clever.There are a couple other solutions I use that work in Java as well.

1. Write a test specific subclass and override the method you want  to mock out. http://xunitpatterns.com/Test-Specific%20Subclass.html

2. Use the EasyMock class extensions and create a partial mock. http://easymock.org/EasyMock2_3_ClassExtension_Documentation.html

The calling semantics of your test helper is pretty nice though!</description>
		<content:encoded><![CDATA[<p>Very clever.There are a couple other solutions I use that work in Java as well.</p>
<p>1. Write a test specific subclass and override the method you want  to mock out. <a href="http://xunitpatterns.com/Test-Specific%20Subclass.html" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/xunitpatterns.com/Test-Specific_20Subclass.html?referer=');">http://xunitpatterns.com/Test-Specific%20Subclass.html</a></p>
<p>2. Use the EasyMock class extensions and create a partial mock. <a href="http://easymock.org/EasyMock2_3_ClassExtension_Documentation.html" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/easymock.org/EasyMock2_3_ClassExtension_Documentation.html?referer=');">http://easymock.org/EasyMock2_3_ClassExtension_Documentation.html</a></p>
<p>The calling semantics of your test helper is pretty nice though!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

