<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sword Systems &#187; unit test</title>
	<atom:link href="http://swordsystems.com/category/unit-test/feed/" rel="self" type="application/rss+xml" />
	<link>http://swordsystems.com</link>
	<description>Cutting Commentary</description>
	<lastBuildDate>Tue, 15 May 2012 14:50:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grails 2 Unit Tests &#8211; Undocumented Properties</title>
		<link>http://swordsystems.com/2012/05/15/grails-2-unit-tests-undocumented-properties/</link>
		<comments>http://swordsystems.com/2012/05/15/grails-2-unit-tests-undocumented-properties/#comments</comments>
		<pubDate>Tue, 15 May 2012 14:50:27 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=242</guid>
		<description><![CDATA[GrailsUnitTestMixin (and its descendents DomainClassUnitTestMixin, ServiceUnitTestMixin, etc) give your test classes some static and instance variables that aren&#8217;t mentioned in the docs yet. You get applicationContext, grailsApplication, config, and messageSource. Previously, if you had code that needed a grailsApplication (such as the JSON configurations), you had to set it up yourself. Now you get it [...]]]></description>
			<content:encoded><![CDATA[<p><code>GrailsUnitTestMixin</code> (and its descendents <code>DomainClassUnitTestMixin</code>, <code>ServiceUnitTestMixin</code>, etc) give your test classes some static and instance variables that aren&#8217;t mentioned in the docs yet.  You get <code>applicationContext, grailsApplication, config</code>, and <code>messageSource</code>.  Previously, if you had code that needed a grailsApplication (such as the JSON configurations), you had to set it up yourself.  Now you get it for free.  The mixin also implements the <code>shouldFail</code> method from <code>GroovyTestCase</code> so you can keep that functionality even though your tests are now JUnit 4 based.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2012/05/15/grails-2-unit-tests-undocumented-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails 2 Unit Tests &#8211; Using Base Classes</title>
		<link>http://swordsystems.com/2012/05/15/grails-2-unit-tests-using-base-classes/</link>
		<comments>http://swordsystems.com/2012/05/15/grails-2-unit-tests-using-base-classes/#comments</comments>
		<pubDate>Tue, 15 May 2012 14:43:15 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[grails testing]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=228</guid>
		<description><![CDATA[I&#8217;ve been meaning to write up my experiences with upgrading a 1.x app to grails 2 for two months now. Since I can&#8217;t seem to find the time to do a large post, I&#8217;ll follow MrHaki&#8217;s example and sprinkle some nuggets of wisdom around. Here&#8217;s a couple of bits on the new unit testing components. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to write up my experiences with upgrading a 1.x app to grails 2 for two months now.  Since I can&#8217;t seem to find the time to do a large post, I&#8217;ll follow <a href="http://mrhaki.blogspot.com/search/label/Grails" target="_blank">MrHaki&#8217;s</a> example and sprinkle some nuggets of wisdom around.  Here&#8217;s a couple of bits on the new unit testing components.</p>
<p>First, read <a href="http://naleid.com/blog/2012/05/01/upgrading-to-grails-2-unit-testing/" title="Grails 2 unit testing" target="_blank">Ted Naleid</a>&#8216;s great writeup.  He encountered many of the same issues I found and documented them in great detail.  Plus he has a list of other reference pages.</p>
<p>Second, as Ted mentions, there are problems using a base class for tests.  This is especially true if you have JUnit annotations in the base class like <code>@Before</code>.  Instead, turn your base class into a generic POGO and then use the @TestMixin annotation to include it in your tests.  </p>
<pre class="brush: groovy; title: ; notranslate">
class MyAppTestSupport {
    //...useful common properties and methods here....
}
</pre>
<p>Then in your test class:</p>
<pre class="brush: groovy; title: ; notranslate">
@TestFor(MyDomainClass)
@TestMixin(MyAppTestSupport)
class MyDomainClassTests {
    //you can access the properties and methods from MyAppTestSupport here just as
    //if they were part of your class
}
</pre>
<p>This makes it a little harder to jump to routines in the mixed-in class in an IDE (at least Intellij gets a bit confused), but the tests will run consistently.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2012/05/15/grails-2-unit-tests-using-base-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails, Maven, packaging, and skipTests fun</title>
		<link>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/</link>
		<comments>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 16:25:55 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[frustration]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=62</guid>
		<description><![CDATA[The grails maven plugin honors the maven.test.skip option (which turns off compiling and executing tests), but not the skipTests option (which only turns off executing tests). This means that you cannot easily create a package with test classes in it without running all of the tests. I finally come up with a close work around: [...]]]></description>
			<content:encoded><![CDATA[<p>The grails maven plugin honors the <code>maven.test.skip</code> option (which turns off compiling and executing tests), but not the <code>skipTests</code> option (which only turns off executing tests).  This means that you cannot easily create a package with test classes in it without running all of the tests.  I finally come up with a close work around:<br />
<code><br />
mvn clean grails:exec install -Dcommand=test-app -Dargs="-unit DoesNotExist" -Dmaven.test.skip=true<br />
</code><br />
By explicitly listing the <code>test-app</code> command but specifying a test that does not exist, I was able to get the unit tests to be compiled.  Since I only needed some common testing files in my package, this works for me.  If someone wanted to package both the unit and integration tests, I don&#8217;t think this would work.  I filed a new issue in the <a href="http://jira.codehaus.org/browse/GRAILS-6188">Grails Jira</a> to try to get a real resolution.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cruising on other people&#8217;s work</title>
		<link>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/</link>
		<comments>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 14:48:26 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=23</guid>
		<description><![CDATA[I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main Grails Plugin site and, sure enough, someone else has already written a Grails [...]]]></description>
			<content:encoded><![CDATA[<p>I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main <a href="http://grails.org/plugin/category/all" target="_blank">Grails Plugin</a> site and, sure enough, someone else has already written a <a href="http://grails.org/plugin/settings" target="_blank">Grails Settings</a> plugin.  It needs a few enhancements to do what I want, but it&#8217;s better than starting from scratch.  While I was perusing the plugin list, I found a few others that can replace features I had started to sketch out (like <a href="http://grails.org/plugin/taggable" target="_blank">Taggable</a>) and was inspired by yet others that would let me easily add features that I hadn&#8217;t thought of before (like <a href="http://grails.org/plugin/commentable" target="_blank">Commentable </a>and <a href="http://grails.org/plugin/sparkline" target="_blank">Sparkline</a>).</p>
<p>Another example is yet another good <a href=" http://agileice.blogspot.com/2009/09/grails-integration-testing.html" target="_blank">post</a> by my friend and coworker Jeff Erikson detailing his research into problems with Grails config options getting wiped during integration tests.  I had been meaning to write up a note about how the GrailsUnitTestCase class hides the true config settings, so you don&#8217;t want to accidentally use it in integration tests.  Jeff took my little tip a lot farther with his post.  Thanks, Jeff!</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy Categories vs ExpandoMetaClass</title>
		<link>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/</link>
		<comments>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 19:23:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[category]]></category>
		<category><![CDATA[ExpandoMetaClass]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=4</guid>
		<description><![CDATA[I first saw Groovy in Nov 2007 and promptly decided to dive in over my head and write a DSL in it. One thing that I never quite got was why one would want to use a Category versus ExpandoMetaClass. Having to create a class with a bunch of static methods and then surround other [...]]]></description>
			<content:encoded><![CDATA[<p>I first saw Groovy in Nov 2007 and promptly decided to dive in over my head and write a DSL in it.  One thing that I never quite got was why one would want to use a Category versus ExpandoMetaClass.  Having to create a class with a bunch of static methods and then surround other classes in it didn&#8217;t seem very elegant.  Directly adding behavior to a class with an ExpandoMetaClass is much more straightforward.  I thought that the Category approach must be a hold over from Groovy releases prior to 1.5 when ExpandoMetaClass was added.  The only use case I could come up with for them was if you wanted to add the same functionality to a set of classes &#8211; sort of an AOP view of things.</p>
<p>But then Groovy 1.6 came out and I saw that the team had added some very cool annotations to make categories even more powerful and easier to use.  (See <a href="http://www.infoq.com/articles/groovy-1-6 ">InfoQ </a>for a great write up of the 1.6 features.)  Okay &#8211; you don&#8217;t improve a dead feature, so what was I missing?</p>
<p>This past weekend I got a chance to ask the person from whom I first learned about Groovy, Scott Davis.  His Blue Pill and Red Pill talks at NFJS were what first got my mind churning about the possibilities that Groovy opened up.  Before sitting in on another of his talks at the most recent NFJS conference this past weekend, I asked him why one would use categories in a DSL rather than modifying meta classes? His answer told me that I was asking the wrong question.  The strength of categories is in scoping &#8211; modifying behavior for a limited period of time.  The primary example he gave was for unit tests.  A category can short circuit certain behavior (like retrieving info from a DB or from a file) to make it easier to test certain behavior in isolation.  This makes a lot of sense.  Mocks/stubs have their place;  they are useful when you need to work with an object in a very limited sense &#8211; just a few calls.  Then there are times when you want a real object doing 95% of what it is supposed to do, but you want to take over in just a few situations to be able to insert custom behavior.  e.g. in a unit test when you want to short circuit network or file-based activity or you want to purposefully force an error condition.</p>
<p>It so happens that I really need to improve the unit tests for some network-based components in the ETL system that I work with.  The primary one is called GetHttpContent, so you can imagine that unit testing it can be a pain.  I&#8217;ll give Categories a closer look to see if they can help me out.  Unfortunately, I have to wait until we finish shifting to a our new project structure because right now there are so many dependencies in the primary project that if I work on a groovy file in that project in Eclipse I lose ~20M of memory every time I edit it.  But the limitations (and benefits) of the Eclipse groovy plugin can wait for another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

