<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>chris clarke</title>
	<link>http://squadlimber.com/chris</link>
	<description>software development that works...or something</description>
	<pubDate>Mon, 07 Apr 2008 23:14:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Outsourcing My Own Project</title>
		<link>http://squadlimber.com/chris/2008/04/07/outsourcing-my-own-project/</link>
		<comments>http://squadlimber.com/chris/2008/04/07/outsourcing-my-own-project/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 22:00:25 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Agile Planning</category>

		<category>Testing</category>

		<category>Outsourcing</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2008/04/07/outsourcing-my-own-project/</guid>
		<description><![CDATA[I&#8217;ve decided to outsource one of my own pet projects, I just don&#8217;t realistically have enough time to work on it but I would still like to see it come to life.  I&#8217;m using a site called RentACoder to hire a developer to do the coding.  I don&#8217;t really know quite yet how [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to outsource one of my own pet projects, I just don&#8217;t realistically have enough time to work on it but I would still like to see it come to life.  I&#8217;m using a site called <a href="http://www.rentacoder.com/">RentACoder</a> to hire a developer to do the coding.  I don&#8217;t really know quite yet how I&#8217;m going to run it, I&#8217;ve started by writing some acceptance criteria, and I&#8217;ll be testing it myself by writing some automated acceptance tests.  Ideally I&#8217;d like to give these tests to the developer first but I&#8217;m not really sure how all this RentACoder stuff works yet - should be a fun experiment!</p>
<p>One of the more interesting things about starting a RentACoder project is the options they present to you regarding time of delivery:</p>
<p><img id="image96" src="http://squadlimber.com/chris/wp-content/uploads/2008/04/deliverytimerentacoder.png" alt="deliverytimerentacoder.png" /></p>
<p>I&#8217;m sure we&#8217;ve all been on one of those Option One &#8220;Project must be delivered in X days&#8221; types.  I&#8217;ve been lucky enough to be on a few Option Two projects and even a few Option One projects where we&#8217;ve negotiated what will be delivered in X days and in what priority.  As my project has no deadline and I don&#8217;t want my Programmer-For-Hire to rush and reduce quality in order to meet a deadline, I plumped for Option Three.</p>
<p>I quite like the question regarding Managing Coder Estimates - its like your signing up to a contract agreeing that all programmers underestimate by either 2 or 5 times!</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2008/04/07/outsourcing-my-own-project/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mocking Concrete Classes in JMock 2</title>
		<link>http://squadlimber.com/chris/2007/11/15/mocking-classes-in-jmock-2/</link>
		<comments>http://squadlimber.com/chris/2007/11/15/mocking-classes-in-jmock-2/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 10:44:22 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Tools n Stuff</category>

		<category>Testing</category>

		<category>Java</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/11/15/mocking-classes-in-jmock-2/</guid>
		<description><![CDATA[In JMock 1 you extended the cglib version of MockObjectTestCase but in JMock 2 its different.  You need to change the Imposteriser used by the Mockery:

Mockery context = new Mockery&#40;&#41;;
context.setImposteriser&#40;ClassImposteriser.INSTANCE&#41;;
&#160;
]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.jmock.org/">JMock 1</a> you extended the cglib version of MockObjectTestCase but in <a href="http://www.jmock.org/">JMock 2</a> its different.  You need to change the Imposteriser used by the Mockery:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
Mockery context = <span style="color: #000080;">new</span> Mockery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
context.<span style="color: #000000;">setImposteriser</span><span style="color: #000000;">&#40;</span>ClassImposteriser.<span style="color: #000000;">INSTANCE</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/11/15/mocking-classes-in-jmock-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tool Support For JavaScript</title>
		<link>http://squadlimber.com/chris/2007/08/06/tool-support-for-javascript/</link>
		<comments>http://squadlimber.com/chris/2007/08/06/tool-support-for-javascript/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 00:57:04 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Tools n Stuff</category>

		<category>Testing</category>

		<category>JavaScript</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/08/06/tool-support-for-javascript/</guid>
		<description><![CDATA[Oh dear, what happened to my clever navigation and code-completion? The IDE support for JavaScript is still catching up with Java, if you have only small amounts of JavaScript you&#8217;ll be fine with TextMate or something similar.  But for large class-based projects you&#8217;ll need something else.

The best thing at the moment is IntelliJ, its [...]]]></description>
			<content:encoded><![CDATA[<p>Oh dear, what happened to my clever navigation and code-completion? The IDE support for JavaScript is still catching up with Java, if you have only small amounts of JavaScript you&#8217;ll be fine with <a href="http://macromates.com/">TextMate</a> or something similar.  But for large class-based projects you&#8217;ll need something else.</p>
<p><img align="right" id="image81" src="http://squadlimber.com/chris/wp-content/uploads/2007/08/hammers.jpg" alt="hammers.jpg" /></p>
<p>The best thing at the moment is <a href="http://www.jetbrains.com/idea/">IntelliJ</a>, its currently the only thing out there that can navigate <em>across</em> a codebase.  With <a href="http://www.aptana.com/">Aptana</a> or <a href="http://www.eclipse.org/">Eclipse</a>, if the method exists in another file it cannot navigate to it and you&#8217;re forced to resort to searching in files ending with *.js.  Second best is Eclipse 3.3 with the <a href="http://labs.adobe.com/technologies/jseclipse/">JSEclipse 2.0 pre-release</a> installed.  (I&#8217;m really impressed with Eclipse 3.3 - its improved in several places - but I especially like the <a href="http://quicksilver.blacktree.com/">Quicksilver</a> style Ctrl-3 shortcut).</p>
<h3>How hard can unit-testing JavaScript be?</h3>
<p>On the surface of things JavaScript seems to have a lot of the same tools that Java has for unit-testing.  <a href="http://www.jsunit.net/">JSUnit</a> is the JavaScript equivalent of <a href="http://www.junit.org/">JUnit</a> and <a href="http://jsmock.sourceforge.net/">JSMock</a> the equivalent of <a href="http://www.jmock.org/">JMock</a>.</p>
<p>The syntax of JSUnit is fine, its pretty much as you&#8217;d expect and conforms to the XUnit conventions.  The key bit that&#8217;s missing is the fast feedback.  When working on a class you want to be able to run the test often so you can see the immediate effects of changes you&#8217;ve made and the let the test tell you exactly whats wrong.  To run a test with JSUnit, I need to open the JSUnit test runner in a browser, load my test page and then run it.  Once I&#8217;ve run it, assuming its failed I get a list of tests that failed - but not the reason they failed, I need to double-click - then I get an alert telling me why the test failed.  It really interrupts your flow, especially when you&#8217;re flipping between multiple classes.  If you&#8217;re using an IDE with a Browser Preview tab, you can get around this problem with a little JavaScript along the lines of:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">var</span> currentLocation = <span style="color: #3366CC;">&quot;&quot;</span>&nbsp; &nbsp;window.<span style="color: #006600;">location</span>;<br />
window.<span style="color: #006600;">location</span> = <span style="color: #3366CC;">&quot;file:///.../testRunner.html?testpage=&quot;</span>&nbsp; &nbsp;currentLocation&nbsp; <span style="color: #3366CC;">&quot;&amp;amp;autoRun=true&quot;</span>;<br />
&nbsp;</div>
<p>(Sorry plus signs don&#8217;t seem to show up - hopefully you can get the general idea).</p>
<p>I&#8217;ve got this working in Eclipse by installing the <a href="http://prdownloads.sourceforge.jp/amateras/24128/tk.eclipse.plugin.htmleditor_2.0.4.zip">EclipseHTMLEditor plugin</a> and including the following common bit of code in all JSUnit tests:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">var</span> currentLocation = <span style="color: #3366CC;">&quot;&quot;</span>&nbsp; &nbsp;window.<span style="color: #006600;">location</span>;<br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>currentLocation.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;cacheBuster&quot;</span><span style="color: #66cc66;">&#41;</span> &lt; <span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; window.<span style="color: #006600;">location</span> = <span style="color: #3366CC;">&quot;file:///.../testRunner.html?testpage=&quot;</span>&nbsp; &nbsp;currentLocation&nbsp; <span style="color: #3366CC;">&quot;&amp;amp;autoRun=true&quot;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div>
<p>Now a test can be run by just clicking on its Preview tab.</p>
<h3>Making a Mockery</h3>
<p>JSMock is kind of good - at least someone&#8217;s written a mocking framework for JavaScript.  As soon as you start to use it - you realize that it is by know means a mature piece of software.</p>
<p>It doesn&#8217;t give you any kind of useful messages, for example it will say &#8216;Unexpected Arguments&#8217; but won&#8217;t tell you what the actual arguments were against the expected arguments.  Similarly for an unexpected invocation, it won&#8217;t tell you what has been called and what was expected to be called.  The other missing piece is support for literal objects - JSMock gets it wrong if you pass a literal object as an argument.  This is basic stuff - thankfully the code is still quite small and I&#8217;ve found myself adding a lot of these features myself just to be able to use it.</p>
<p>The cool thing about JSMock is that because JavaScript is such a flexible language you don&#8217;t need to put your method calls in strings like in JMock 1 and you can keep using literal language (unlike in JMock 2):</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
&nbsp; server.<span style="color: #006600;">expect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">request</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'/index.jsp'</span>, <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; method: <span style="color: #3366CC;">'get'</span>,<br />
&nbsp; &nbsp; parameters: <span style="color: #66cc66;">&#123;</span> userId: <span style="color: #3366CC;">'fred'</span> <span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; onSuccess: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div>
<p>Another cool thing is that if I have static objects as collaborators I can mock those too:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">var</span> mockThing = mockControl.<span style="color: #006600;">createMock</span><span style="color: #66cc66;">&#40;</span>Thing<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #009900; font-style: italic;">// substitute the mock Thing for the real Thing</span><br />
Thing = mockThing;<br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/08/06/tool-support-for-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Red, Green, Cup of Tea</title>
		<link>http://squadlimber.com/chris/2007/05/02/red-green-cup-of-tea/</link>
		<comments>http://squadlimber.com/chris/2007/05/02/red-green-cup-of-tea/#comments</comments>
		<pubDate>Wed, 02 May 2007 20:55:23 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Continuous Integration</category>

		<category>Testing</category>

		<category>Refactoring</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/05/02/red-green-cup-of-tea/</guid>
		<description><![CDATA[I like the Red Green Refactor pattern - write a failing test, make the test go green and then refactor the code.  However, I&#8217;ve found recently that refactor doesn&#8217;t necessarily mean make the code tidier or improve the design to some people.  To some people it just means change some existing code.  [...]]]></description>
			<content:encoded><![CDATA[<p>I like the <a href="http://www.jamesshore.com/Blog/Red-Green-Refactor.html">Red Green Refactor</a> pattern - write a failing test, make the test go green and then refactor the code.  However, I&#8217;ve found recently that refactor doesn&#8217;t necessarily mean <em>make the code tidier</em> or <em>improve the design</em> to some people.  To some people it just means <em>change some existing code</em>.  <img id="image64" src="http://squadlimber.com/chris/wp-content/uploads/2007/05/cup_of_tea.jpg" alt="cup_of_tea.jpg" align="right"/>  </p>
<p>So I invented (by accident) the Red Green Cup of Tea pattern - write a failing test, make the test go green, and go and make a cup of tea whilst the build runs.  I&#8217;ve found that whilst making a cup of tea, my pair and I can reflect on what we&#8217;ve just done and often find we weren&#8217;t 100% happy with what we just did.  We then set our cups of tea back down on the desk and <a href="http://c2.com/cgi/wiki?WhatIsRefactoring">Refactor</a> the code.
</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/05/02/red-green-cup-of-tea/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What is an end to end test?</title>
		<link>http://squadlimber.com/chris/2007/02/14/what-is-an-end-to-end-test/</link>
		<comments>http://squadlimber.com/chris/2007/02/14/what-is-an-end-to-end-test/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 20:57:42 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Testing</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/?p=29</guid>
		<description><![CDATA[In my latest role we&#8217;ve been tasked with re-writing an existing end-to-end testing infrastructure.  Whilst going through, understanding and improving the existing infrastructure, I started to think about exactly what an end-to-end test is and what it should do.
A quick google for end-to-end test reveals a few examples of how other people view end [...]]]></description>
			<content:encoded><![CDATA[<p>In my latest role we&#8217;ve been tasked with re-writing an existing end-to-end testing infrastructure.  Whilst going through, understanding and improving the existing infrastructure, I started to think about exactly what an end-to-end test is and what it should do.</p>
<p>A quick google for end-to-end test reveals a few examples of how other people view end to end testing:</p>
<ul>
<li>
<strong><em>automated diagnostic routines tailored specifically for the system under test.</em></strong></p>
<p>- taken from a test for an electronic warfare system.  In this case they <u>send several low-level signals through the system and make assertions based on the outputs</u>.</p>
</li>
<li><strong><em>Component tests can be incrementally combined until they provide a validation of the entire process flow.</em></strong>
<p>- taken from a testing tool - in this case an end to end test is viewed as simply the <u>sum of several component (unit &#038; integration) tests</u>.</p>
</li>
<li>
<strong><em>Commands and telemetry are usually transmitted between TKSC and Kibo through the U.S. segment of the ISS, via the Tracking and Data Relay Satellite (TDRS). This time, however, the test was conducted by linking TKSC via JSC to the Kibo PM, which is currently located at KSC. This test closely simulated the actual configuration for the planned Kibo operations.</em></strong></p>
<p>- taken from a space station test - in this case the end to end test seems to be a <u>run-through (or rehearsal)</u> of what will actually happen in the real system.  However, in this case, they can&#8217;t use a real test satellite, so they mock that part out by locating the component at a remote lab.
</li>
</ul>
<p>I see this as three separate ways of doing an end-to-end test:</p>
<ol>
<li><strong>Don&#8217;t</strong> - each component is well-tested and each interaction is tested with an integration test.  (Therefore - the sum of these parts becomes your end-to-end test.) Imagine an end-to-end test that tests end-points A-D. If you have integration tests that cover points A-B, B-C, and C-D, then you already are testing A-D.</li>
<li><strong>Automated low-level</strong> - you throw stuff in and you get stuff back.  But the danger is that this doesn&#8217;t prove that the system works, it just proves it behaves in the way you expect it to.  Thinking back to the Electronic Warfare System, chucking signals through the components may prove logical correctness, but maybe the only way to really test it is to turn the key and  push the big red button.</li>
<li><strong>Simulation</strong> - you take as much of the real system as possible and start pushing those buttons.  Of course the danger here is that you don&#8217;t have so many boundary tests and it can be hard to simulate failure - imagine trying to test the satellite falling out of orbit.</li>
</ol>
<h3>Dude where are my end-points?</h3>
<p>One common thing amongst a lot of the end-to-end tests is that they seemed to have one single end-point i.e. they put something in and expect something back:<br />
<img id="image31" src="http://squadlimber.com/chris/wp-content/uploads/2007/02/normalendpoints.jpg" alt="normalendpoints.jpg" /></p>
<p>  The model used is different to the end-to-end testing infrastructure I have been looking at today.  In this model, the infrastructure has several end-points:</p>
<p><img id="image30" src="http://squadlimber.com/chris/wp-content/uploads/2007/02/eggsendpoints.jpg" alt="eggsendpoints.jpg" /></p>
<p>In this model, the three end-points cause most of the problems:</p>
<ol>
<li><strong>The tests become white box</strong> - the infrastructure <i>knows</i> about the inner-workings of the system.  These <em>inner-workings should be irrelevant and should be covered by component-level testing</em>.</li>
<li><strong>The tests are surplus</strong> - they <em>cover things already covered by unit and integration tests</em>.</li>
<li><strong>The tests are brittle</strong> - the infrastructure has inner knowledge of the system - it does selects on the database and scrapes webpages - these things change as the code develops therefore the tests break often - not because the tests fail but because the <i>test infrastructure code is too dependent on inner-workings and breaks often</i>.</li>
<li><strong>The tests are testing multiple products</strong> - if you have multiple end-points this would indicate that your test is actually testing multiple products.  Taking the example above - what is being tested? The order viewer, the order taker, or the supplier interface.  The answer is they are all being tested, but individually - so you actually <em>no longer have an end-to-end test - the test is a collection of component tests.</em></li>
</ol>
<p>So, a possible solution to this would be to break the test in to three end-to-end tests:</p>
<ol>
<li>Test the Order Viewer - order an egg - see that it behaves correctly on the Viewer.</li>
<li>Test Ordering An Egg - put stuff in one end and check you get back an egg.</li>
<li>Test Ordering An Egg From The Supplier - ask the supplier for some eggs and check you get them.</li>
</ol>
<p>Simple, right? But it all get&#8217;s a bit more complicated when scenarios enter the scene.</p>
<h3>Test Scenarios</h3>
<p>Test scenarios are essentially dress-rehearsals for things that a customer can do with your product.  Look back at the satellite example - they need to run-through what happens when the product is up in orbit and in contact with mission control.</p>
<p>Looking at the Egg System, let&#8217;s have a scenario as follows:</p>
<p>Customer already has an egg on order.  They want to cancel the egg order.  So the request to cancel the order is sent in to the system, the cancel needs to be visible to customer support on the Egg Order Viewer and the cancel needs to be forwarded to the supplier correctly.</p>
<p>Woah, hang on a minute, we&#8217;re back to the three end-points, we need to check that order gets sent in and we get a confirmation from the Egg Order Taker, check we can see the cancel on the Egg Order Viewer and check the right stuff gets sent by the Egg Supplier Interface.</p>
<p>Or do we? Let&#8217;s take another look.</p>
<p>The scenario can be rewritten as:</p>
<ol>
<li>The customer rings telephone number and says &#8220;Cancel my egg!!!&#8221;. </li>
<li>If the customer&#8217;s egg is gone. Customer happy. Test passed.</li>
</ol>
<p>But wait&#8230;</p>
<ol>
<li>The customer rings telephone number and says &#8220;I changed my mind!! Don&#8217;t cancel my egg!!!&#8221;.</li>
<li>The operator looks on the order viewer, and stops the cancel. Customer happy. Test passed.</li>
</ol>
<p>There&#8217;s a lot of other scenarios here but essentially we&#8217;re only using two interfaces - the Order System in the first case and the Order View in the second case.  We don&#8217;t care about the supplier in these cases because it doesn&#8217;t matter for the product - you need to be able to order and call up and find out what&#8217;s going on with your order - that&#8217;s it.</p>
<p><img id="image32" src="http://squadlimber.com/chris/wp-content/uploads/2007/02/splitscenarios.jpg" alt="splitscenarios.jpg" /></p>
<p>So, now we&#8217;ve defined these interfaces - it&#8217;s easy to re-write the end-to-end testing infrastructure:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #000080;">interface</span> OrderAnEgg <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">void</span> sendAnOrder<span style="color: #000000;">&#40;</span>Order order<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; Notifications<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> waitForFeedback<span style="color: #000000;">&#40;</span>Order order<span style="color: #000000;">&#41;</span>;<br />
<br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000080;">interface</span> ViewAndChangeAnEggOrder <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; OrderDetails view<span style="color: #000000;">&#40;</span>Order order<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">void</span> change<span style="color: #000000;">&#40;</span>Order order, Change change<span style="color: #000000;">&#41;</span>;<br />
<br />
<span style="color: #000000;">&#125;</span><br />
&nbsp;</div>
<h3>Test of much as the real system as possible</h3>
<p>Back to the thing we learned early on - end to end tests test as much of the real system as possible.  In the particular project I&#8217;m working on this is the hard part, the application is deployed across multiple containers, load-balanced, on hard-to-obtain environments etc&#8230; etc&#8230;</p>
<p>Time is a constraint here, so it&#8217;s possible to mock some of these things that don&#8217;t really matter and simulate a lot of the others.  But now comes an important point - if you can&#8217;t test it - should you release it?  For example, if it&#8217;s not possible to say simulate multiple containers, then is the application really production-ready, should it be deployed, is it essentially untested and therefore not safe?  Probably not, but it&#8217;s something to definitely think about.</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/02/14/what-is-an-end-to-end-test/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unit Tests In Javascript</title>
		<link>http://squadlimber.com/chris/2007/01/15/unit-tests-in-javascript/</link>
		<comments>http://squadlimber.com/chris/2007/01/15/unit-tests-in-javascript/#comments</comments>
		<pubDate>Mon, 15 Jan 2007 00:40:46 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Testing</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/?p=23</guid>
		<description><![CDATA[Looking around for AJAX libraries to use for storyboard following a retrospective around the initial development, I stumbled across scriptaculous, one of the benefits being that it has it&#8217;s own unit test library.
An alternative may be to use jsUnit which has syntax much more familiar to anyone who&#8217;s ever used JUnit.
After I wrote the storyboard [...]]]></description>
			<content:encoded><![CDATA[<p>Looking around for AJAX libraries to use for <a target="_blank" href="http://squadlimber.com/storyboard/storyboard.html">storyboard</a> following a <a target="_blank" href="http://squadlimber.com/chris/?p=21">retrospective around the initial development</a>, I stumbled across <a target="_blank" href="http://script.aculo.us/">scriptaculous</a>, one of the benefits being that it has it&#8217;s own unit test library.<br />
An alternative may be to use <a target="_blank" href="http://www.jsunit.net/">jsUnit</a> which has syntax much more familiar to anyone who&#8217;s ever used JUnit.</p>
<p>After I wrote the storyboard retrospective, I happened across <a target="_blank" href="http://joe.truemesh.com/blog/">Joe Walnes blog</a> where I found <a target="_blank" href="http://joe.truemesh.com/blog//000649.html">Building testable AJAX apps (Does my button look big in this?)</a>.  It was nice to see someone had a similar thoughts to myself as to why you would   approach a Javascript project differently than you would any  normal project; quoting Joe:<br />
<em>“What’s a bit annoying is that we know all this stuff already. And certainly we do this in any other type of <span class="caps">GUI</span> development, but when I came to first doing ajax I thought ‘oh. it’s just javascript, don’t really take it seriously, just wire up a little event in the html’ and it’s almost like we’ve regressed back to the VB days when you built a whole <span class="caps">GUI</span> by saying ‘Right, first I’m going to draw a button, then I’m going to put an onclick to the button then I’m going to write 10,000 lines of code on the onclick.’”  </em></p>
<p>There were several other interesting things in Adam and Joes talk.  They chose not to use Google Web Toolkit despite working for Google and in fact they did not appear to use any AJAX or Javascript libraries/frameworks apart from JsUnit.  The best idea they had was to take a great approach to the application borrowing from ideas that you would use when developing a traditional GUI  application (including Michael Feathers&#8217; <a target="_blank" href="http://www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf">The Humble Dialog Box</a>).  They used a kind of Model View Controller to make the app more testable.  In fact they were able to test some code in the controller without requiring a browser using <a target="_blank" href="http://www.mozilla.org/rhino/">Rhino Engine</a>.  The way they tested the view was most interesting: they did it manually - well almost - they had written a small bit of helper code that made all UI functions available to play around with in a sidebar.  The sidebar also showed any Javascript events that had been fired (see image).</p>
<p><code class="tiny"><a title="joeandadamtestapp.jpg" class="imagelink" href="http://squadlimber.com/chris/wp-content/uploads/2007/01/joeandadamtestapp.jpg"><img alt="joeandadamtestapp.jpg" id="image24" src="http://squadlimber.com/chris/wp-content/uploads/2007/01/joeandadamtestapp.thumbnail.jpg" /></a><br />
</code></p>
<p>This seemed like a really logical way to test the UI controls and view of a GUI because often the only way to test usability is to <em>use</em> something.  Also, making assertions on pixel widths and things just seems silly and static screen grabs are&#8217;nt the same thing as actualling using the app - so why not manually test it - especially nice if you can get some real users.</p>
<p>After speaking to someone in the pub about AJAX development, I was pointed towards two very useful looking tools.  <a target="_blank" href="http://www.prototypejs.org/">Prototype</a> is a JavaScript Framework which provides some useful libraries and also some really useful extensions to the standard DOM.  For example, using the extensions you can do cool stuff like this found at <a target="_blank" href="http://www.sergiopereira.com/articles/prototype.js.html">Sergio Pereiras site</a>:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">function</span> findEmployeeById<span style="color: #66cc66;">&#40;</span>emp_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> listBox = $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'lstEmployees'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> options = listBox.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; options = $A<span style="color: #66cc66;">&#40;</span>options<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> opt = options.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>employee<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>employee.<span style="color: #006600;">value</span> == emp_id<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>opt.<span style="color: #006600;">innerHTML</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">//displays the employee name</span><br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div>
<p>The $() operator is just a shortcut for document.getElementById(), and the $A() operator converts an element to an array, you can see how this function works based on the html below:</p>
<pre>
&lt;select id="lstEmployees" size="10"&gt;
    &lt;option value="5"&gt;Buchanan, Steven&lt;/option&gt;
    &lt;option value="8"&gt;Callahan, Laura&lt;/option&gt;
    &lt;option value="1"&gt;Davolio, Nancy&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>The other useful tool is <a target="_blank" href="http://www.thefrontside.net/crosscheck">Crosscheck</a> which is a cross-browser testing framework which doesn&#8217;t actually require any browsers.  This seems like a very useful solution for cross-browser compatibility testing of storyboard.
</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/01/15/unit-tests-in-javascript/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
