<?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>Jamie&#039;s Space &#187; Unit Testing</title>
	<atom:link href="http://www.jamiepenney.co.nz/category/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamiepenney.co.nz</link>
	<description>Thoughts and Works of a Software Engineer</description>
	<lastBuildDate>Wed, 05 Oct 2011 01:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Testing content_for in Rails 3.x Helpers with RSpec</title>
		<link>http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/</link>
		<comments>http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 05:37:43 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[rails rpsec]]></category>

		<guid isPermaLink="false">http://www.jamiepenney.co.nz/?p=98</guid>
		<description><![CDATA[After having a quick look around the net (and not finding anything up to date and useful) I came up with the following basic test structure for testing my ApplicationHelper methods that served up content_for things like page titles, javascript includes, etc: 1 2 3 4 5 6 7 8 9 10 require 'spec_helper' &#160; <a href='http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>After having a quick look around the net (and not finding anything up to date and useful) I came up with the following basic test structure for testing my ApplicationHelper methods that served up content_for things like page titles, javascript includes, etc:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'spec_helper'</span>
&nbsp;
describe ApplicationHelper <span style="color:#9966CC; font-weight:bold;">do</span>
  describe <span style="color:#996600;">&quot;title&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;should call content_for(:title) with the title passed&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      helper.<span style="color:#9900CC;">title</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;title stuff&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      helper.<span style="color:#9900CC;">content_for</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> == <span style="color:#996600;">&quot;title stuff&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NHibernate and the Repository Pattern</title>
		<link>http://www.jamiepenney.co.nz/2009/12/12/nhibernate-and-the-repository-pattern/</link>
		<comments>http://www.jamiepenney.co.nz/2009/12/12/nhibernate-and-the-repository-pattern/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 20:43:43 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://jamiepenney.co.nz/?p=54</guid>
		<description><![CDATA[I&#8217;ve been writing a small time tracker web application to teach myself ASP.Net MVC, and am using NHibernate as the ORM.  I&#8217;m trying to use best practises while building this app, and one issue I was trying to deal with was whether to build a layer over the top of NHibernate. My first set of <a href='http://www.jamiepenney.co.nz/2009/12/12/nhibernate-and-the-repository-pattern/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">I&#8217;ve been writing a small time tracker web application to teach myself <a href="http://www.asp.net/mvc">ASP.Net MVC</a>, and am using NHibernate as the ORM.  I&#8217;m trying to use best practises while building this app, and one issue I was trying to deal with was whether to build a layer over the top of NHibernate. My first set of controller actions used NHibernate directly, with a dependency injected ISessionFactory. This was fine for simple queries (like get Task with id 1) but it meant more and more of my model concerns were leaking into my Controllers. I had thought that NHibernate provided enough of an abstraction over my model for this to not matter, but I was quite wrong.</p>
<p style="text-align: left;">Remembering I had seen some argument over whether using a generic repository was a good idea or not, I started searching around and found quite a few blogs saying it was a bad idea. They made sense, and one blog had a <a href="http://www.noctovis.net/blog/index.php/2009/01/22/my-thoughts-about-irepository/">great solution</a>: Create a Repository&lt;T, U&gt; abstract class for common CRUD style operations, inherit your specific Repository from that, and only expose meaningful methods in your interface to client code. The benefits of this approach are many &#8211; your client code can only see methods that are applicable to each model class, you don&#8217;t have to duplicate your common CRUD operations for each model class, and it is easy as pie to unit test.</p>
<p style="text-align: left;">This last point is the one worth mentioning in my books. The great thing about separation of concerns is it should make things easier to pull apart for unit testing. Because my Repository methods have meaningful names, and are pretty fine grained, my mocking setup looks almost readable. It is immediately obvious from reading my tests that TaskController.List(5) should call ITaskRepository.GetLatestTasks(5). Not only that, but most of the Controller actions have been reduced to &#8220;Get this from Repository, return to View&#8221; or &#8220;Save this thing to the Repository&#8221;. They are small, obvious methods, and that makes them easier to test, and easier to maintain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamiepenney.co.nz/2009/12/12/nhibernate-and-the-repository-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UI Design, Unit Testing, and Related Pains</title>
		<link>http://www.jamiepenney.co.nz/2008/03/29/ui-design-unit-testing-and-related-pains/</link>
		<comments>http://www.jamiepenney.co.nz/2008/03/29/ui-design-unit-testing-and-related-pains/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 06:49:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Contracting]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://65.99.219.219/wordpress/?p=15</guid>
		<description><![CDATA[Background Currently I am working on merging two of the steps in the Workbench part of ArchAngel. The final two steps of the generation process used to be the actual generation of the files you wanted, and the analysis to see which files needed to be merged. This was two screens, one in which the <a href='http://www.jamiepenney.co.nz/2008/03/29/ui-design-unit-testing-and-related-pains/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>Currently I am working on merging two of the steps in the Workbench part of ArchAngel. The final two steps of the generation process used to be the actual generation of the files you wanted, and the analysis to see which files needed to be merged. This was two screens, one in which the user picked the groups of files to generate, and the other which showed conflict resolution. Only after all conflicts had been resolved could the newly generated and merged files be copied into the user&#8217;s project directory.</p>
<h3>UI Changes</h3>
<p>This wasn&#8217;t as easy as it could be. There is no reason why the user needs to go through an additional screen to choose the files &#8211; why not just put that on the screen with the analysis so they could choose which files they wanted to keep? So Gareth merged the two screens, shifting the file choosing part to the tree view with checkboxes, and showing the results of the analysis as an icon next to the file in the tree.</p>
<h3>Process Changes</h3>
<p>One thing Gareth wanted to do was generate the files in the background. I set up a process whereby the files would be generated on a background thread, and if the user changed any options in the project, the files would be regenerated. Hopefully most of the files would be generated by the time the user actually got to the final generate and merge screen. We also do the analysis on the same thread once the generation is done.</p>
<h3>Unit Testing</h3>
<p>This process is really the meat of the ArchAngel Workbench &#8211; the majority of the processing happens here. Thus I wanted to make sure that I wasn&#8217;t breaking anything by implementing this background processing, as I had to make a number of changes to make it thread-safe. So I embarked on a quest to make this part of the system as easy to unit test as possible.</p>
<p>I started by completely removing any trace of GUI code from the generation code. This meant removing the background worker references, and replacing all of the code dealing with threading with a helper class I created. This class encapsulated progress reporting and task cancellation, so that we can mock these aspects during testing.</p>
<p>Mocking is a major focus of this process &#8211; I want to be able to mock out as much of the system as possible in order to make the unit tests more focused. The thing with mocking/faking the major components in the system is that we can write these mocks/fakes once, and reuse them in all of our tests. This is better than relying on resetting the state of the major components &#8211; this is prone to failure if those components change in future. Also it is difficult to prevent behaviour that relies on the underlying environment, such as writing to files and reading from settings files.</p>
<p>On Monday I will start working on creating some mocks for these components, and will add another post with my experiences of this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamiepenney.co.nz/2008/03/29/ui-design-unit-testing-and-related-pains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Update on Unit Testing</title>
		<link>http://www.jamiepenney.co.nz/2008/03/24/quick-update-on-unit-testing/</link>
		<comments>http://www.jamiepenney.co.nz/2008/03/24/quick-update-on-unit-testing/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 06:51:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Contracting]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://65.99.219.219/wordpress/?p=14</guid>
		<description><![CDATA[Just thought I would add one more blog post to the millions of others floating around the net about how great unit testing is. I&#8217;ve spent the last week or so designing and implementing a cleaner version of one of the major modules of ArchAngel, and I couldn&#8217;t have done it without the regression test <a href='http://www.jamiepenney.co.nz/2008/03/24/quick-update-on-unit-testing/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Just thought I would add one more blog post to the millions of others floating around the net about how great unit testing is. I&#8217;ve spent the last week or so designing and implementing a cleaner version of one of the major modules of ArchAngel, and I couldn&#8217;t have done it without the regression test suite I wrote. It picked up all of those tiny little bugs that you just look over, but will cause you massive grief later on because they exist in parts of the code that &quot;should just work&quot;.</p>
<p>The number one lesson I&#8217;ve learned from this is to never assume anything works, even very simple things.</p>
<p>I started reading Pragmatic Unit Testing in C# with NUnit (<a title="http://www.pragprog.com/titles/utc2/pragmatic-unit-testing-in-c-with-nunit-2nd-ed" href="http://www.pragprog.com/titles/utc2/pragmatic-unit-testing-in-c-with-nunit-2nd-ed">http://www.pragprog.com/titles/utc2/pragmatic-unit-testing-in-c-with-nunit-2nd-ed</a>) a few days into the design phase, and although I was doing some unit testing it pushed me into implementing more and better tests. It is a really good introduction to both how to unit test, as well as what to test. I highly recommend it for anyone working in C#. They have a Java/JUnit one there too, but I haven&#8217;t read that one.</p>
<p>In short: Unit testing saved my sanity this week.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamiepenney.co.nz/2008/03/24/quick-update-on-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

