<?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>Tea-Driven Development &#187; unit testing</title>
	<atom:link href="http://blog.mattwynne.net/tag/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattwynne.net</link>
	<description>Matt Wynne taking it one tea at a time</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:07:10 +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>jsUnit vs jsUnit</title>
		<link>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/</link>
		<comments>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 20:33:02 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Agile / Lean Software Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/</guid>
		<description><![CDATA[If, like me, you&#8217;ve been confused by the two different, identically-named, unit testing frameworks for javascript, here&#8217;s a very useful explanation of their strengths, weaknesses, and purposes.]]></description>
			<content:encoded><![CDATA[<p>If, like me, you&#8217;ve been confused by the <a href="http://www.jsunit.net/">two</a> <a href="http://jsunit.berlios.de/">different</a>, identically-named, unit testing frameworks for javascript, <a href="http://wiki.openqa.org/display/SRC/Selenium+RC+and+JsUnit">here&#8217;s a very useful explanation</a> of their strengths, weaknesses, and purposes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Awesome Acceptance Testing</title>
		<link>http://blog.mattwynne.net/2008/03/18/awesome-acceptance-testing/</link>
		<comments>http://blog.mattwynne.net/2008/03/18/awesome-acceptance-testing/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 21:52:42 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Agile / Lean Software Development]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2008/03/18/awesome-acceptance-testing/</guid>
		<description><![CDATA[My notes on DanNorth and JoeWalnes&#8216; session at Spa 2008. Five artefacts: Automation &#8211; the glue that binds the tests to the code Vocabulary &#8211; the language that the tests are expressed in Syntax &#8211; the technology that the tests are expressed in (C#, Java) Intent &#8211; the actual scenario being tested Harness &#8211; the [...]]]></description>
			<content:encoded><![CDATA[<p>My notes on <a href="http://dannorth.net/">DanNorth</a> and <a href="http://www.xpdeveloper.net/xpdwiki/Wiki.jsp?page=JoeWalnes">JoeWalnes</a>&#8216; session at Spa 2008.</p>

<p>Five artefacts:</p>

<ul>
<li>Automation &#8211; the glue that binds the tests to the code</li>
<li>Vocabulary &#8211; the language that the tests are expressed in</li>
<li>Syntax &#8211; the technology that the tests are expressed in (C#, Java)</li>
<li>Intent &#8211; the actual scenario being tested</li>
<li>Harness &#8211; the thing that runs the tests and tells you if they passed</li>
</ul>

<p>Four roles. People might fill more than one, or more than one person might be in a role:</p>

<ul>
<li>Stakeholder</li>
<li>Analyst</li>
<li>Tester</li>
<li>Developer</li>
</ul>

<p>Taking a requirement, the Stakeholder and the Analyst have a conversation:</p>

<ul>
<li>what does that requirement <em>mean</em>?</li>
<li>how can we create a shared understanding?</li>
</ul>

<p>Then the Analyst and the Tester have a conversation:</p>

<ul>
<li>what is the scope of (&#8216;bigness&#8217;) of this requirement?</li>
<li>how will we know when we&#8217;re done?</li>
<li>=&gt; Scenarios (examples)</li>
</ul>

<p>Tester then &#8216;monkeyfies&#8217; the scenarios, using the following template:</p>

<p><strong>Given</strong> &#8230;
- assumptions, context in which the scenario occurs.</p>

<p><strong>When</strong> &#8230;
- user action, interaction with the system</p>

<p><strong>Then</strong> &#8230;
- expected outcome</p>

<p>e.g.
<strong>Given</strong> we have an account holder Joe
and their current account contains $100
and the interest rate is 10%
<strong>When</strong> Joe withdraws $120
<strong>Then</strong> Joe&#8217;s balance should be $-22</p>

<p>The tester and the developer sit down and write an automated test to implement each scenario.</p>

<p>You might chain these up, but you can always categorise test code into these three partitions. This really helps how you look at test code.</p>

<h4>Consistency Validation Between &#8216;Units&#8217;</h4>

<p>See the <a href="http://martinfowler.com/articles/consumerDrivenContracts.html">Consumer Driven Contracts</a> paper on <a href="http://martinfowler.com">Martin Fowler</a>&#8216;s website.</p>

<h4>Tooling for Automation</h4>

<p>Consider extending / creating the domain model to cover the application itself &#8211; the UI, the back end.</p>

<p>Loads of tools are availlable. Use whatever works and build on it.</p>

<h4>Building a Vocabulary</h4>

<p>Ubiquitous Language &#8211; Start with a shared language. It becomes ubiquitous when it appears <em>everywhere</em> &#8211; documents, code, databases, conversations.</p>

<p>You will use different vocabularies in different <em>bounded contexts</em>. A context might be your problem domain, testing domain, software domain, or the user interface domain.</p>

<p>Beware which roles understand you when you&#8217;re talking in a particular domain. Often terms will span domains.</p>

<p>e.g. NHibernateCustomerRepository
&lt;&#8211;  1 &#8211;&gt;&lt;&#8211; 2&#8211;&gt;&lt;&#8211; 3  &#8211;&gt;</p>

<p>1 = 3rd Party Provider Domain
2 = Problem Domain
3 &#8211; Software Domain</p>

<p>Make your tests tell a story &#8211; make it flow. Don&#8217;t hide away things in Setup methods that will make the test hard to read. If that means a little bit of duplication, so be it. &#8216;Damp not DRY&#8217;.</p>

<h4>Syntax &#8211; Implementing Your Tests</h4>

<ul>
<li>write your own</li>
<li>keep it simple. don&#8217;t fart around writing too fancy a DSL. you&#8217;ll be surprised what testers / analysts / stakeholders will be prepared to read.</li>
<li>great way to learn</li>
<li>Jbehave2</li>
<li>training wheels?</li>
<li><a href="http://rspec.info/">rspec</a></li>
<li>very nice.</li>
<li>create templates for each given / when / then which you can plug together with parameter values into scenarios</li>
<li><a href="http://fit.c2.com/">fit</a></li>
<li><a href="http://www.concordion.org/">concordion</a></li>
<li><a href="http://nbehave.org/">nbehave</a> &#8211; <a href="http://www.lostechies.com/blogs/joe%5Focampo/">joe ocampo</a></li>
</ul>

<p>Basically what you need is a way to assemble different permutations and combinations of Given / When / Then with different parameters to make different scenarios.</p>

<h4>Expressing Intent</h4>

<p>Think in terms of narrative, flow. Think in terms of bounded contexts, and who the audience (role) is for that context. Who will understand that vocabulary?</p>

<p>Make sure the intent is clear &#8211; that&#8217;s the main thing.</p>

<h4>Harness</h4>

<p>Do you want to hook into continuous integration build?</p>

<p>Which version of the code is it going to run against?</p>

<p>Keep the tests in two buckets:
* in progress
* done</p>

<p>Those which are in the &#8216;done&#8217; bucket, <strong>should always work</strong>, those which are in progress are allowed to be failing, until you make them pass.</p>

<h4>Getting Started</h4>

<p>Things you can do today.</p>

<ul>
<li>Try it for your next requirement</li>
<li>Given When Then helps guide the tests</li>
<li>It&#8217;s a collaborative process &#8211; get people involved</li>
<li>Works for bug fixes</li>
<li>a bug is a scenario that you missed in the first place
use the tools you&#8217;re most comfortable with</li>
<li>doesn&#8217;t have to be perfect</li>
</ul>

<h4>Down The Line</h4>

<p>What to aim for.</p>

<ul>
<li><strong>ALL</strong> requirements have acceptance criteria specified up front</li>
<li><a href="http://www.springerlink.com/content/vcq847l8ker3jc1d/">helps with estimation</a></li>
<li>acceptance tests are automated <em>where appropriate</em></li>
<li>just having thought about it helps &#8211; you may come back to automating it later.</li>
<li>Push button, availlable to all.</li>
<li>helps build trust with stakeholders</li>
</ul>

<h4>Advice</h4>

<ul>
<li>Automate pragmatically</li>
<li>Don&#8217;t try to automate what you can&#8217;t do manually</li>
<li>Testing is validating an <em>outcome</em> against <em>intention</em></li>
<li>Non functional requirements</li>
<li>Plan for false positives</li>
<li>Quality is a variable</li>
<li>doesn&#8217;t mean you don&#8217;t go test first</li>
<li>doesn&#8217;t mean low quality code</li>
<li>does mean <em>how complete is the solution</em>? &#8211; how many scenarios / edge cases are you going to try and meet?</li>
</ul>

<h4>Summary</h4>

<ul>
<li>Have a shared understanding of <strong>done</strong></li>
<li>There is no Golden Hammer</li>
<li>Be aware of the five aspects of test automation</li>
<li>Automation, Vocabulary, Syntax, Intent, Harness</li>
<li>Start simple, then you can benefit now</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2008/03/18/awesome-acceptance-testing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integration Tests &#8211; Good or Evil?</title>
		<link>http://blog.mattwynne.net/2007/07/10/integration-tests-good-or-evil/</link>
		<comments>http://blog.mattwynne.net/2007/07/10/integration-tests-good-or-evil/#comments</comments>
		<pubDate>Tue, 10 Jul 2007 11:58:42 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2007/07/10/integration-tests-good-or-evil/</guid>
		<description><![CDATA[As with most stupid questions like this, the answer is &#8220;neither&#8221;. There are times when integration tests really help, and there are times when they can be a pain in the neck. I was prompted to write this post when a colleague pointed me towards this page on the behaviour-driven wiki, which mentions the disadvantages [...]]]></description>
			<content:encoded><![CDATA[<p>As with most stupid questions like this, the answer is &#8220;neither&#8221;. There are times when integration tests really help, and there are times when they can be a pain in the neck.</p>

<p>I was prompted to write this post when  a colleague pointed me towards <a href="http://behaviour-driven.org/BehaviourDrivenProgramming">this page </a>on the behaviour-driven wiki, which mentions the disadvantages of integration tests, which usually involve some complex (and often slow to run) procedure to set up an expected state in the system your code is integrating with. This tight coupling with the external system reduces agility and makes the test code brittle.</p>

<p>The page does point out that “even in this state the code is often much more robust and a much better functional fit than code developed under more traditional methods based on large-scale up-front design”</p>

<p>I agree with the principles in the article, and I believe BDD is a great way to think, but I do think as long as the integration tests are well-factored (and hence easy to change) then the problems highlighted don’t apply – you’re still going to be quick on your feet if requirements change.</p>

<p>The question is whether you’re going to spend more time fixing your unit tests than you would debugging the code – if you’re confident you can write it correctly first time <strong>and</strong> anybody needing to change it is highly unlikely to introduce bugs in the area you’re coding, it’s a waste of everybody’s time to write a unit test – the test just becomes baggage for the team to drag around.</p>

<p>Conversely, if there’s a risk that future changes could break what you’re coding, or you’re bored of hitting F5 in the browser to test some subtle tweak in a function way down deep in a subsystem, thinking of an imaginative way to write a lightweight unit test that isolates that function and proves that it works as you want it to, is probably going to save you some dull debugging time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2007/07/10/integration-tests-good-or-evil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

