<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>XPlayer &#187; Design</title>
	<atom:link href="http://xplayer.wordpress.com/category/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://xplayer.wordpress.com</link>
	<description>eXtreme Programming e mondo agile</description>
	<lastBuildDate>Mon, 09 Nov 2009 22:23:59 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>it</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='xplayer.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/3cfc994993561e3fe29b8d0033c0dace?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>XPlayer &#187; Design</title>
		<link>http://xplayer.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://xplayer.wordpress.com/osd.xml" title="XPlayer" />
		<item>
		<title>Think different about mock objects!</title>
		<link>http://xplayer.wordpress.com/2009/11/04/think-different-about-mock-objects/</link>
		<comments>http://xplayer.wordpress.com/2009/11/04/think-different-about-mock-objects/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 23:02:57 +0000</pubDate>
		<dc:creator>stoner</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Mock Objects]]></category>

		<guid isPermaLink="false">http://xplayer.wordpress.com/?p=106</guid>
		<description><![CDATA[Another (different) point of view on mock object, too much times used merely as a testing tool. They are more then that, and knowing how to use it in a better way may improve your code too!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=106&subd=xplayer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div>Recently, after the post on mock objects by Uncle Bob (<a href="http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses" target="_blank">&#8220;Manual Mocking: Resisting the Invasion of Dots and Parentheses&#8221;</a>), a rather long discussion thread grown in the extreme programming italian newsgroup (starting <a href="http://it.groups.yahoo.com/group/extremeprogramming-it/message/7224" target="_blank">here</a>, but careful, it&#8217;s in italian, sorry!).</div>
<div>This led me to think more deeply about my experience with mock objects, and I&#8217;d like to share my point of view here, as it&#8217;s quite different (or so it seems to me) from the common opinions on this important topic.</div>
<p><div>I&#8217;ve always followed the so-called (as Giuliano would say, isn&#8217;t it <a href="http://thinkingbox.wordpress.com/" target="_blank">Giuliano</a>? :-) &#8220;English School&#8221; of mock objects, the one coming from the pioneering works of <a href="http://www.planningcards.com/iterex/blog.html" target="_blank">Tim Mackinnon</a>,<a href="http://www.m3p.co.uk/blog/" target="_blank"> Steve Freeman</a> and <a href="http://www.natpryce.com/" target="_blank">Nat Pryce</a>, the real fathers of mock objects.</div>
<p><div>And I&#8217;ve always carefully followed their advice, first through their *epic* paper  <strong>&#8220;Mock Roles, not Objects&#8221;</strong> (<a href="http://www.jmock.org/oopsla2004.pdf" target="_blank">http://www.jmock.org/oopsla2004.pdf</a>) &#8211; IMHO the best paper on mock objects and on object oriented programming with mocks &#8211; then through their terrific posts on the blog <a href="http://www.mockobjects.com/" target="_blank">www.mockobjects.com</a>, and finally, through their first (and brand new) book, <a href="http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627" target="_blank">&#8220;Growing Object-Oriented Software, Guided by Tests&#8221;</a>.</div>
<p><div>One thing I learn is that <strong>mock objects are a design tool</strong>, while many people see it only as a technique for speeding up unit tests.</div>
<div>And in this context mock objects are a key tool to support your TDD process, especially in test-driving your domain model, where you follow a process similar to traditional top-down development, in which you start from the highest level of abstraction and then proceed, layer by layer, to reach the core of the domain and then move again towards the boundary of the system, towards the &#8220;services&#8221; (you can find many similarities in <a href="http://alistair.cockburn.us/Hexagonal+architecture" target="_blank">Cockburn&#8217;s approach to Hexagonal Architecture</a>).</div>
<p><div>Then, when you reach the domain boundary, you should stop using mocks.</div>
<div>Mock objects are useful to TDDing the thin adapter layers to your services (that is, third-party libraries or external components (e.g. a database, a JMS queue, &#8230;). But then, the actual adapters will be tested with integration testing.</div>
<p><div>Why?</div>
<p style="padding-left:30px;">Because you should use mock objects as far as you can apply TDD, whereas you can design and *discover* interfaces (and roles), and assign responsibility. On the other hand, in front of a third-party library you cannot follow this process, since the code is not under your control, and you cannot modify it.</p>
<p><div style="padding-left:30px;">Because if you use mock objects with third-party libraries (two concrete examples taken from our recent projects: isolating our tests from the database in a Rails app, or in a java app using Hibernate ORM), you&#8217;ll write tests that *guess* the library behaviour, and your guesses may be far away from the actual behaviour.</div>
<div style="padding-left:30px;">Raise your hands if you never burnt your fingers with this kind of test with mocks, where maybe you *thought* you had a save() method to return an A object while in fact it returned B object! :)</div>
<p><div style="padding-left:30px;">And finally, because this kind of tests with mocks end up to be long, unreadable and fragile (an &#8220;invasion of dots and parentheses&#8221; reported by Uncle Bob in his post), full of mocks and mock expectations. And, hey, you cannot refactor them, since you don&#8217;t own the third-party code!</div>
<p><BR><br />
To verify the correct integration with libraries or external components, which are out of you domain, as well as with integration tests, you may use <a href="http://xunitpatterns.com/Fake%20Object.html" target="_blank">fake</a>s or <a href="http://xunitpatterns.com/Test%20Stub.html" target="_blank">stub</a>s (and, by the way, the example in the Uncle Bob&#8217;s post is actually a stub, not a &#8220;hand-rolled mock&#8221;).</p>
<p><div>So, I&#8217;ll repeat myself, following this &#8220;mocks as a design tool&#8221; approach, you&#8217;ll <a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html" target="_blank">mock only types you own</a>.</div>
<p><div>Some useful references to study this topic in depth (you&#8217;ll be OK even if you read just the first 2-3 links :-)</div>
<div>
<ul>
<li><a href="http://www.jmock.org/oopsla2004.pdf" target="_blank">http://www.jmock.org/oopsla2004.pdf</a> (I&#8217;m quoting again this paper, because it&#8217;s a *really* good starting point to understand this approch to mock objects)</li>
<li><a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html" target="_blank">http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html</a> (if you like to deepen the &#8220;Don&#8217;t mock third-party libraries&#8221; and &#8220;Don&#8217;t mock value objects&#8221; topics)</li>
<li><a href="http://www.mockobjects.com/2006/10/tell-dont-ask-and-mock-objects.html" target="_blank">http://www.mockobjects.com/2006/10/tell-dont-ask-and-mock-objects.html</a></li>
<li><a href="http://www.mockobjects.com/2006/10/jmock-listening-to-opinionated.html" target="_blank">http://www.mockobjects.com/2006/10/jmock-listening-to-opinionated.html</a></li>
<li><a href="http://www.mockobjects.com/2006/09/like-fire-drill.html" target="_blank">http://www.mockobjects.com/2006/09/like-fire-drill.html</a></li>
<li><a href="http://www.mockobjects.com/2007/04/test-smell-bloated-constructor.html" target="_blank">http://www.mockobjects.com/2007/04/test-smell-bloated-constructor.html</a></li>
<li><a href="http://www.mockobjects.com/2007/04/test-smell-i-need-to-mock-object-i-cant.html" target="_blank">http://www.mockobjects.com/2007/04/test-smell-i-need-to-mock-object-i-cant.html</a></li>
<li><a href="http://www.mockobjects.com/files/evolving_an_edsl.ooplsa2006.pdf" target="_blank">http://www.mockobjects.com/files/evolving_an_edsl.ooplsa2006.pdf</a> (yet another paper, very good)</li>
<li> and if you want to know more about the history of mock objects: <a href="http://www.mockobjects.com/2009/09/brief-history-of-mock-objects.html" target="_blank">http://www.mockobjects.com/2009/09/brief-history-of-mock-objects.html</a></li>
</ul>
<p>I hope I give you some useful feedback on this topic!</p>
</div>
<div>And, by the way, feedbacks are warmly welcome!</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xplayer.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xplayer.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xplayer.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xplayer.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xplayer.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xplayer.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xplayer.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xplayer.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xplayer.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xplayer.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=106&subd=xplayer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://xplayer.wordpress.com/2009/11/04/think-different-about-mock-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d4e7e22b936262bcf5c87b43f4f370c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stoner</media:title>
		</media:content>
	</item>
		<item>
		<title>Perche&#8217; non si dovrebbero mockizzare classi concrete</title>
		<link>http://xplayer.wordpress.com/2007/05/30/perche-non-si-dovrebbero-mockizzare-classi-concrete/</link>
		<comments>http://xplayer.wordpress.com/2007/05/30/perche-non-si-dovrebbero-mockizzare-classi-concrete/#comments</comments>
		<pubDate>Wed, 30 May 2007 13:03:26 +0000</pubDate>
		<dc:creator>stoner</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Mock Objects]]></category>
		<category><![CDATA[OOPrinciples]]></category>

		<guid isPermaLink="false">http://xplayer.wordpress.com/2007/05/30/perche-non-si-dovrebbero-mockizzare-classi-concrete/</guid>
		<description><![CDATA[Mi sono sempre chiesto perche&#8217; mai Steve Freeman e gli altri &#8216;padri&#8217; dei Mock Objects e dello stile di testing interaction-based sconsigliassero di fare mock di classi concrete, tanto che jMock ed EasyMock non supportavano questa possibilita&#8217; &#8216;nativamente&#8217;, ma si doveva installare un&#8217;estensione a parte, che usa la famosa libreria CGLIB (per inciso con il [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=19&subd=xplayer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Mi sono sempre chiesto perche&#8217; mai Steve Freeman e gli altri &#8216;padri&#8217; dei Mock Objects e dello stile di testing interaction-based sconsigliassero di fare mock di classi concrete, tanto che <em>jMock </em>ed <em>EasyMock </em>non supportavano questa possibilita&#8217; &#8216;nativamente&#8217;, ma si doveva installare un&#8217;estensione a parte, che usa la famosa libreria <em>CGLIB </em>(per inciso con il nuovo jMock 2 e&#8217; possibile fare mock di classi concrete, ma si deve usare la classe UnsafeHackConcreteClassImposteriser, ed il nome dice tutto di come scoraggino questa pratica).</p>
<p>Tanto che tempo fa avevo anche commentato un <a href="http://www.mockobjects.com/2006/10/jmock-listening-to-opinionated.html#comments" title="Commento al post di Freeman">post di Freeman</a> chiedendogli perche&#8217; lui giudicasse il mock di classi concrete come una sorta di ultima possibilita&#8217; da adottare solo in casi di emergenza (es quando si affronta codice legacy particolarmente ostico e <em>chiuso</em>). E lui mi aveva risposto cosi&#8217;:</p>
<blockquote><p><font color="#000000"><em>Because then the interface is implicit, which means you can&#8217;t see it and you haven&#8217;t given it a name. Instead of using the test to expose a feature of the design, you have more to think about whenever you&#8217;re working in that area: is the method overwritten? is it in a super class? what about the state of the rest of the class I&#8217;m extending? That sort of thing.</em></font></p>
<p><font color="#000000"><em>For me, the CGLIB should have a &#8220;Break Glass in Case of Emergency&#8221; written on the front. It&#8217;s useful in tight situations, but not to be recommended.</em></font></p></blockquote>
<p>Eppero&#8217; nonostante la sua risposta la cosa non mi era ancora chiara fino in fondo.<br />
Poi un recente post su mockobjects.com (<a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html"><strong>Test Smell: Mocking concrete classes</strong></a>) mi ha finalmente aiutato a capire meglio le cose.</p>
<p>Il fatto e&#8217; che lo scopo del TDD con i Mock Objects e&#8217; quello di scoprire e far emergere relazioni tra oggetti, e dare nomi a queste relazioni. Se pero&#8217; si mantiene la relazione tra oggetti a livello di classi concrete, queste relazioni rimangono per cosi&#8217; dire piu&#8217; nascoste, implicite, e quindi diventa difficile individuarle e darle un nome.</p>
<p>Cito direttamente il post, laddove spiega cosa non va con i mock di classi concrete:</p>
<blockquote><p><font color="#000000"><em>The problem with this approach is that it leaves the relationship between the objects implicit.<br />
I hope we&#8217;ve made clear by now that <strong>the intention of Test-Driven Development with Mock Objects is to discover relationships between objects</strong>.<br />
If I subclass, there&#8217;s nothing in the domain code to make such a relationship visible, just methods on an object. This makes it harder to see if the service that supports this relationship might be relevant elsewhere and I&#8217;ll have to do the analysis again next time I work with the class.</em></font></p></blockquote>
<p><img src="//dictionarytip/skin/book.png" style="border:1px solid blue;z-index:90;position:absolute;left:505px;top:293px;" /></p>
<p>Addirittura si spinge a dire che lasciando le relazioni tra oggetti a livello di classi concrete, si rischia di violare l&#8217;<a href="http://www.objectmentor.com/resources/articles/isp.pdf">Interface Segregation Principle</a>, perche&#8217; le classi dipendono da una interfaccia piu&#8217; grande di quella che usano veramente.</p>
<p>E poi poco piu&#8217; avanti spiega che l&#8217;approccio <em>mockist</em> aiuta anche a dare nomi alle relazioni ed ai ruoli, e a ragionare piu&#8217; in termini di dominio piuttosto che di implementazione:</p>
<blockquote><p><font color="#000000"><em>There&#8217;s a more subtle but powerful reason for not mocking concrete classes.<br />
As part of the TDD with Mocks process, I have to think up names for the relationships I discover—in this example the <code>ScheduledDevice</code>. I find that this makes me think harder about the domain and teases out concepts that I might otherwise miss.<br />
Once something has a name, I can talk about it. </em></font></p></blockquote>
<p>Il tutto e&#8217; poi riassunto bene nell&#8217;altro post, <a href="http://www.mockobjects.com/2007/05/what-tests-will-tell-you.html">What the tests will tell you</a>, da leggere e rileggere, dove elenca alcuni benefici derivanti dall&#8217;approccio TDD+MockObjects</p>
<ul>
<li><em>Keeping knowledge local</em></li>
<li><em>If it&#8217;s explicit I can name it</em></li>
<li><em>More names mean more domain information</em></li>
<li><em>Pass behaviour rather than data</em></li>
</ul>
<p>Detto questo, ammetto che sono sempre stato affascinato da questo approccio ma non ho mai trovato la forza necessaria per decidere di applicarlo un po&#8217; piu&#8217; sistematicamente, metterlo alla prova insomma.</p>
<p>Un po&#8217; perche&#8217; nel mio team da sempre si usa l&#8217;approccio classico, e l&#8217;approccio interaction-based e&#8217; visto con qualche dubbio/sospetto, un po&#8217; perche&#8217; i nostri progetti per ora sono tutti Java 1.4 e quindi buona parte delle comodita&#8217; delle versioni piu&#8217; recenti dei framework jMock e Easymock te le perdi (soprattutto la loro maggiore <em>letteralita&#8217;</em>, cosa importante per avere dei test validi).</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/xplayer.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/xplayer.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xplayer.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xplayer.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xplayer.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xplayer.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xplayer.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xplayer.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xplayer.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xplayer.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xplayer.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xplayer.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=19&subd=xplayer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://xplayer.wordpress.com/2007/05/30/perche-non-si-dovrebbero-mockizzare-classi-concrete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d4e7e22b936262bcf5c87b43f4f370c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stoner</media:title>
		</media:content>

		<media:content url="//dictionarytip/skin/book.png" medium="image" />
	</item>
		<item>
		<title>Ascoltare i propri test: quando la lunghezza di un costruttore ci puo&#8217; insegnare tanto&#8230;</title>
		<link>http://xplayer.wordpress.com/2007/05/15/ascoltare-i-propri-test-quando-la-lunghezza-di-un-costruttore-ci-puo-insegnare-tanto/</link>
		<comments>http://xplayer.wordpress.com/2007/05/15/ascoltare-i-propri-test-quando-la-lunghezza-di-un-costruttore-ci-puo-insegnare-tanto/#comments</comments>
		<pubDate>Tue, 15 May 2007 13:15:07 +0000</pubDate>
		<dc:creator>stoner</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Mock Objects]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://xplayer.wordpress.com/2007/05/15/ascoltare-i-propri-test-quando-la-lunghezza-di-un-costruttore-ci-puo-insegnare-tanto/</guid>
		<description><![CDATA[Ancora una volta i post su mockobjects.com mi ricordano che c&#8217;e&#8217; molto da imparare dai propri test. E&#8217; il caso di Test Smell: Bloated Constructor e Test Smell: Everything is mocked.

Se si usa il TDD, capita di finire per avere oggetti con un costruttore gigante, che prende una lista infinita di parametri, tipicamente i peers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=12&subd=xplayer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ancora una volta i post su mockobjects.com mi ricordano che c&#8217;e&#8217; molto da imparare dai propri test. E&#8217; il caso di <a href="http://www.mockobjects.com/2007/04/test-smell-bloated-constructor.html">Test Smell: Bloated Constructor</a> e <a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html">Test Smell: Everything is mocked.</a></p>
<p><a href="http://xplayer.files.wordpress.com/2007/05/dscf1963.jpg" title="Bloated Constructor…"><img src="http://xplayer.files.wordpress.com/2007/05/dscf1963.thumbnail.jpg" alt="Bloated Constructor…" align="middle" /></a></p>
<p>Se si usa il TDD, capita di finire per avere oggetti con un costruttore gigante, che prende una lista infinita di parametri, tipicamente i peers (ovvero i collaboratori) dell&#8217;oggetto. In tali casi fare i test, e soprattutto farli coi mock, e&#8217; la morte. E in molti casi ce la si prende coi mock, rei di complicare i test.</p>
<p>Ma spesso la difficolta&#8217; a testare un oggetto e&#8217; sintomo di problemi di design sull&#8217;oggetto stesso&#8230;  E riflettere su queste difficolta&#8217; e riportarle sul codice sotto test ci consente di migliorarne il design. O, come dice Steve Freeman, <em>being sensitive to complexity in the tests can help me clarify my designs.</em></p>
<p>In questo caso un costruttore lungo potrebbe indicare che magari ci sono oggetti che potrebbero essere raggruppati a formare un nuovo oggetto. Questo semplifica anche i test dell&#8217;oggetto da cui siamo partiti e consente di ridurre le sue responsabilita&#8217;, tutte cose buone e giuste.</p>
<p>Freeman usa due euristiche per l&#8217;estrazione di componenti:</p>
<blockquote><p><em>When I&#8217;m extracting implicit components, I look first for two conditions: arguments that are always used together in the class, and that have the same lifetime. That usually finds me the concept, then I have the harder task of finding a good name.</em></p></blockquote>
<p>Nel secondo post che cito all&#8217;inizio, <a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html">Test Smell: Everything is mocked</a>, si sfata un mito duro a morire: non si devono fare mock per tutte le classi che si incontrano.</p>
<p>In particolare non e&#8217; assolutamente necessario mockizzare value objects, e soprattutto &#8220;don&#8217;t mock third-party libraries!&#8221;. Piuttosto, un approccio migliore e&#8217; quello di far emergere col TDD e i mock un sottile straterello di codice che faccia da adaptor verso le API esterne, e che fornisca al nostro dominio i servizi di cui ha bisogno.</p>
<p><img src="http://www.mockobjects.com/uploaded_images/mockable-adaptor-752684.png" height="192" width="256" /></p>
<p>E poi testare questo thin layer con dei test di integrazione che garantiscano che ci si agganci correttamente alla libreria.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/xplayer.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/xplayer.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xplayer.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xplayer.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xplayer.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xplayer.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xplayer.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xplayer.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xplayer.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xplayer.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xplayer.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xplayer.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=12&subd=xplayer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://xplayer.wordpress.com/2007/05/15/ascoltare-i-propri-test-quando-la-lunghezza-di-un-costruttore-ci-puo-insegnare-tanto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d4e7e22b936262bcf5c87b43f4f370c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stoner</media:title>
		</media:content>

		<media:content url="http://xplayer.files.wordpress.com/2007/05/dscf1963.thumbnail.jpg" medium="image">
			<media:title type="html">Bloated Constructor…</media:title>
		</media:content>

		<media:content url="http://www.mockobjects.com/uploaded_images/mockable-adaptor-752684.png" medium="image" />
	</item>
		<item>
		<title>Ascoltare i propri test, ovvero migliorare il codice partendo dagli smell dei propri test</title>
		<link>http://xplayer.wordpress.com/2007/04/26/ascoltare-i-propri-test-ovvero-migliorare-il-codice-partendo-dagli-smell-dei-propri-test/</link>
		<comments>http://xplayer.wordpress.com/2007/04/26/ascoltare-i-propri-test-ovvero-migliorare-il-codice-partendo-dagli-smell-dei-propri-test/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 12:36:26 +0000</pubDate>
		<dc:creator>stoner</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Mock Objects]]></category>
		<category><![CDATA[OOPrinciples]]></category>
		<category><![CDATA[Testability]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://xplayer.wordpress.com/2007/04/26/ascoltare-i-propri-test-ovvero-migliorare-il-codice-partendo-dagli-smell-dei-propri-test/</guid>
		<description><![CDATA[Steve Freeman e Nat Pryce hanno iniziato una serie di interessanti post sul loro blog mockobjects sul tema dei Test Smells,  ovvero su come &#8216;ascoltare&#8217; i propri test per scoprire possibilita&#8217; di miglioramento nel design del codice sotto test
    In our experience, when we find that our tests are awkward to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=11&subd=xplayer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Steve Freeman e Nat Pryce hanno iniziato una serie di interessanti post sul loro blog <a href="http://www.mockobjects.com">mockobjects </a>sul tema dei <a href="http://www.mockobjects.com/labels/listening%20to%20the%20tests.html">Test Smells,</a>  ovvero su come &#8216;ascoltare&#8217; i propri test per scoprire possibilita&#8217; di miglioramento nel design del codice sotto test</p>
<blockquote><p><em>    In our experience, when we find that our tests are awkward to write, it&#8217;s usually because the design of our target code can be improved.</em></p></blockquote>
<p>Una cosa su cui mi trovo d&#8217;accordo, piu&#8217; che altro perche&#8217; ho avuto la stessa esperienza in passato (e anche nel presente!)</p>
<p><a href="http://xplayer.files.wordpress.com/2007/05/strip_paoladibello.jpg" title="Test Smells…"><img src="http://xplayer.files.wordpress.com/2007/05/strip_paoladibello.jpg?w=1278&#038;h=283" alt="Test Smells…" height="283" width="1278" /></a></p>
<p>Il primo post della serie e&#8217;  <a href="http://www.mockobjects.com/2007/04/test-smell-i-need-to-mock-object-i-cant.html">Test Smell: I need to mock an object I can&#8217;t replace (without magic)</a>,  dove si parte da un codice piuttosto &#8216;chiuso&#8217;, con dipendenze nascoste (magari usando dei Singleton), e passo passo lo si rifattorizza, aprendolo, prima introducendo un fake (o stub che dir si voglia) e poi passando ai mock, mostrando come il codice migliori, prima esplicitando le dipendenze e poi assegnando meglio le responsabilita&#8217;.</p>
<p>Se vi capita dategli un&#8217;occhiata!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/xplayer.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/xplayer.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xplayer.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xplayer.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xplayer.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xplayer.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xplayer.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xplayer.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xplayer.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xplayer.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xplayer.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xplayer.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xplayer.wordpress.com&blog=532244&post=11&subd=xplayer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://xplayer.wordpress.com/2007/04/26/ascoltare-i-propri-test-ovvero-migliorare-il-codice-partendo-dagli-smell-dei-propri-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d4e7e22b936262bcf5c87b43f4f370c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stoner</media:title>
		</media:content>

		<media:content url="http://xplayer.files.wordpress.com/2007/05/strip_paoladibello.jpg" medium="image">
			<media:title type="html">Test Smells…</media:title>
		</media:content>
	</item>
	</channel>
</rss>