<?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>Polymorphic Rants &#187; Testing</title>
	<atom:link href="http://www.lucagrulla.it/blog/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lucagrulla.it/blog</link>
	<description>The blog formerly known as "(s)ragionamenti polimorfici"</description>
	<lastBuildDate>Wed, 16 Jun 2010 09:42:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript testing</title>
		<link>http://www.lucagrulla.it/blog/2010/06/15/javascript-testing/</link>
		<comments>http://www.lucagrulla.it/blog/2010/06/15/javascript-testing/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 22:41:48 +0000</pubDate>
		<dc:creator>Luca</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.lucagrulla.it/blog/?p=243</guid>
		<description><![CDATA[Javascript has become in the last years the language for rich web applications,  but still it rarely receives the level of attention it deserves.
Libraries such jQuery boost our productivity but the code we often end up writing tend  to be a big ball of mud, with an entangled mix of presentation logic, busines logic and server side [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript has become in the last years <em>the</em> language for rich web applications,  but still it rarely receives the level of attention it deserves.</p>
<p>Libraries such <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a> boost our productivity but the code we often end up writing tend  to be a <a title="big bal of mud" href="http://en.wikipedia.org/wiki/Big_ball_of_mud" target="_blank">big ball of mud</a>, with an entangled mix of presentation logic, busines logic and server side interaction,  all incredibly hard to test and to maintain.</p>
<p>It&#8217;s time to move away from this approach and start writing better quality Javascript.</p>
<p>The very first step required to avoid Javascript spaghetti code is start thinking to <strong>Javascript as a</strong><strong> first class language</strong>, and start dealing with it with the same mindset and approach we would use for any server side language.</p>
<p>With this new approach in the same way we identify roles and integration points  in server side code we want to start building <strong>abstractions</strong> in our Javascript codebase.</p>
<p>With the right abstractions in place we are defining clear boundaries between different parts of the system, and as a consequence our code is simpler, we promote reuse  and the <a title="DRY principle" href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">DRY principle</a>, and  we are finally enabling better testing.</p>
<p>Let&#8217;s look at any standard Web 2.0 Javascript code from this new perspective: now the DOM and HTTP are two clear integration points.</p>
<p>Our javascript code manipulates the DOM adding  nodes or changing existing nodes content in the same way any other language would interact with a database. Each call to a server over HTTP via Ajax is exactly the same of calling a web server from our server side code.</p>
<p>With these very two first abstractions in mind, we can start rewriting our code, isolating these interactions behind clearly defined objects.</p>
<p>Now the javascript code is not a ball of mud anymore, but a network of objects that collaborate. With these smaller objects  in place we can now<strong> favour interaction based tests</strong>, moving away from any dependency on the DOM and on the HTTP protocol.</p>
<p>The identified abstractions let me actually mock  and stub things out and test if the different tiers in my javascript code are exchanging the right messages. This separation of concerns keep the business logic nicely isolated from the user interface transformations, enabling also a cleaner state based testing for that specific part of the code (there are no more dependencies on the DOM).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lucagrulla.it/blog/2010/06/15/javascript-testing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EasyMock experience</title>
		<link>http://www.lucagrulla.it/blog/2008/02/23/easymock-experience/</link>
		<comments>http://www.lucagrulla.it/blog/2008/02/23/easymock-experience/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 13:10:17 +0000</pubDate>
		<dc:creator>Luca</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.lucagrulla.it/wordpress/2008/02/23/easymock-experience/</guid>
		<description><![CDATA[For the last two weeks I&#8217;ve worked with EasyMock and coming from a JMock background it&#8217;s easy to make a comparison between the two libraries.
I have to say that I&#8217;m less than impressed by EasyMock: the whole concept of the two different states (recording and active) for the mock library looks unreasonable.
Let&#8217;s look on how [...]]]></description>
			<content:encoded><![CDATA[<p>For the last two weeks I&#8217;ve worked with <a href="http://www.easymock.org/">EasyMock</a> and coming from a JMock background it&#8217;s easy to make a comparison between the two libraries.</p>
<p>I have to say that I&#8217;m less than impressed by EasyMock: the whole concept of the two different states (recording and active) for the mock library looks unreasonable.</p>
<p>Let&#8217;s look on how we can create a mock with EasyMock:<br />
<code> MyInterface mock =EasyMock.mock(MyInterface.class);<br />
//expectation<br />
mock.myMethod();<br />
//activation step<br />
mock.replay();<br />
//actual call to the mock<br />
mock.myMethod();<br />
//verification that the method has been called<br />
mock.verify();<br />
</code><br />
There&#8217;s also a more DSLish style of defining expectations, that I personally prefer (it differentiates clearly  the definition of the expectation from the actual method call).</p>
<p><code> EasyMock.expects(mock.myMethod());</code></p>
<p>This style is the only one available when the expectation is more complex:</p>
<p><code> EasyMock.expects(mock.myMethod()).andReturn(true);</code></p>
<p>But what if I want to define that a certain method will be called on the stub, no matter how many times ?</p>
<p>I can either use a different way of creating the mock:<br />
<code> EasyMock.createNiceMock(MyInterface.class); </code></p>
<p>or using the DSL way:</p>
<p><code>EasyMock.expects(mock.myMethod()).anyTimes() </code></p>
<p>I think that having two ways of defining the same expectation pretty confusing, specially when you&#8217;re using the API for the first time.<br />
What I&#8217;m looking for in a mock library is the possibility of  defining the expectations in a concise but expressive way (DSL please&#8230;) and then inject the dependency in my main object. Period. Done.</p>
<p><a title="JMock" href="http://www.jmock.org/">JMock2</a> is pretty close, but I have to admit the the inner class notation with all those curly brackets around is not helping.</p>
<p>A fellow <a href="http://www.thoughtworks.com">ThoughtWorker</a> have just released <a title="Mockito" href="http://code.google.com/p/mockito/" target="_blank">Mockito</a>: it looks like it&#8217;s taking the best from EasyMock and JMock and put in a single library..will it be true ? I&#8217;ll give it a try and I&#8217;ll let you know <img src='http://www.lucagrulla.it/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lucagrulla.it/blog/2008/02/23/easymock-experience/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
