<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-34908752</id><updated>2008-03-10T16:42:13.341Z</updated><title type='text'>Mock Objects</title><link rel='alternate' type='text/html' href='http://www.mockobjects.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default?start-index=26&amp;max-results=25'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml'/><author><name>Steve Freeman</name></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>55</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-34908752.post-2597209967263939177</id><published>2008-03-08T09:52:00.003Z</published><updated>2008-03-08T11:24:30.404Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='ide'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>Another round in the testability debate</title><content type='html'>&lt;p&gt;This time a &lt;a href="http://blogs.msdn.com/ploeh/default.aspx"&gt;posting&lt;/a&gt; from Mark Seemann has raised a slew of comments.&lt;/p&gt; 
&lt;p&gt;One of them is a note from Colin Jack about the annoyance of producing interface/implementation pairs all the time. My first response is that that sounds to me a bit like a problem with style. Maybe it's just wordplay, but usually I don't &lt;span style="font-style:italic;"&gt;extract&lt;/span&gt; interfaces from classes, I &lt;span style="font-style:italic;"&gt;implement&lt;/span&gt; interfaces that I've already discovered in some previous test.&lt;/p&gt;

&lt;p&gt;My second response is to wonder how much this is a tools issue. I don't believe there's anything in the .Net world that yet matches the responsiveness of the usual Java IDE's. It makes a difference as to what's plausible. I remember the huge shift in perception when first VisualAge for Java and then JetBrains' Idea came out. In retrospect, I always spent more on time on rework than many people I worked with &lt;sup&gt;1&lt;/sup&gt; but it sure took a lot more time in emacs (and I was pretty good at it), even if I was working in a &lt;a href="http://modula3.org/"&gt;better language&lt;/a&gt;.
&lt;/p&gt;

&lt;hr/&gt;
&lt;p&gt;1) which is not to say who was right, I'm just wired that way...&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2008/03/another-round-in-testability-debate.html' title='Another round in the testability debate'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=2597209967263939177' title='3 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2597209967263939177'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2597209967263939177'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-2795194424094785701</id><published>2008-02-12T10:03:00.000Z</published><updated>2008-02-12T10:05:11.787Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'>New Tutorial at QCon</title><content type='html'>On Tuesday 11th March, at QCon London, &lt;a href="http://www.cocking.co.uk/blog/"&gt;Romilly Cocking &lt;/a&gt;and I will be running a new tutorial we're developing with &lt;a href="http://nat.truemesh.com"&gt;Nat Pryce&lt;/a&gt; on 

&lt;a href="http://qcon.infoq.com/london/presentation/TDD+with+MockObjects"&gt;Test-Driven Development with Mock Objects&lt;/a&gt;

following on from a successful first run at the last XpDay. 

Sign up soon!&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2008/02/new-tutorial-at-qcon.html' title='New Tutorial at QCon'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=2795194424094785701' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2795194424094785701'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2795194424094785701'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-865473193129811678</id><published>2008-01-20T11:57:00.000Z</published><updated>2008-01-20T13:26:11.613Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>Just when you thought it was safe to go back in the water...</title><content type='html'>&lt;p&gt;Rising to the bait again (to keep the fishy metaphor going), there's &lt;a href="http://weblogs.asp.net/rosherove/archive/2008/01/18/dependency-injection-is-it-relevant-beyond-unit-testing.aspx"&gt;yet another discussion&lt;/a&gt; of how the ability to hack the runtime changes the world. At one level that's true, but not in this case.&lt;/p&gt;

&lt;p&gt;Dependency Injection is not a recent invention that a cabal of TDDers forced on the world, and it's absolutely not something that we came up with just so we could crowbar in our Mock Objects.&lt;/p&gt;

&lt;p&gt;The relevant design guideline, named the &lt;a href="http://en.wikipedia.org/wiki/Law_of_Demeter"&gt;Law of Demeter&lt;/a&gt; ("Strong Suggestion" isn't very catchy) was first described by Karl Lieberherr in &lt;span style="font-style:italic;"&gt;1987&lt;/span&gt;! The Mock Object pattern came from people applying their substantial O-O experience to TDD in Java, trying to figure out how best to avoid exposing implementation details in unit tests. One of the critical lessons from Demeter is that objects should have explicit dependencies. It helps to keep them focussed on their responsibilities and, as a result, easier to maintain&amp;mdash;and a good way to make dependencies explicit is to pass them in.&lt;/p&gt;

&lt;p&gt;Unfortunately, since then the world seems to have filled up with DI frameworks which cloud what should be a coding style discussion. This is not about having to configure every last corner of your application in XML, this is about how objects, or small clusters of them, get to talk to each other.&lt;/p&gt;

&lt;p&gt;Roy asks, "[...] do you need DI all over the place, or just in specific places where you know dependencies could be a problem?" Well no&amp;mdash;if you have enough foresight to know where those places are. I'm struggling at the moment to test against a framework where everything is helpfully packaged up nice and tight so I can't create an instance of one of its core objects. It's actually well written, but the authors just weren't good enough at prophecy to figure out my particular need. That's why I don't rely just on my intuition, I use the needs of my unit tests to help me figure out where the seams should be. To counter the &lt;a href="http://weblogs.asp.net/rosherove/archive/2008/01/17/is-typemock-too-powerful-will-it-kill-design-for-testability.aspx"&gt;FUD argument&lt;/a&gt;, I have absolutely no problem with saying that I don't want tools that do magic because &lt;span style="font-style:italic;"&gt;I&lt;/span&gt; need guidance with my code.&lt;/p&gt;

&lt;p&gt;As Roy (very politely) concludes, there isn't a high enough proportion of really good code in the world (some of it mine) that we should be in hurry to cut back on techniques such as DI. Just because something has been around for a while doesn't mean it's been superseded, especially in as conventional an environment as .Net.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2008/01/just-when-you-thought-it-was-safe-to-go.html' title='Just when you thought it was safe to go back in the water...'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=865473193129811678' title='8 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/865473193129811678'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/865473193129811678'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-8901297553364329389</id><published>2008-01-13T09:59:00.001Z</published><updated>2008-01-13T10:21:56.373Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='listening to the tests'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>Avoid mega unit tests</title><content type='html'>&lt;p&gt;We've just had a posting to the jMock user list that included the following:&lt;/p&gt;

&lt;blockquote&gt;I was involved in a project recently where JMock was used quite heavily. Looking back, here's what I found:

&lt;ol&gt;
&lt;li&gt;The unit tests where at times unreadable (no idea what they were doing).&lt;/li&gt;
&lt;li&gt;Some tests classes would reach 500 lines in addition to inheriting an
abstract class which also would have up to 500 lines.&lt;/li&gt;
&lt;li&gt;Refactoring would lead to massive changes in test code.&lt;/li&gt;
&lt;/ol&gt;&lt;/blockquote&gt;

&lt;p&gt;I've seen this failure mode on another project I've been helping with, so I think there might be a common pattern.&lt;/p&gt;

&lt;p&gt;I don't think any &lt;i&gt;unit&lt;/i&gt; test code should get that large, except for unusual circumstances. Unit tests are supposed to focus on at most a few classes and shouldn't need a large amount of set up.  What I saw on the other project was enormous amounts of preparation and positioning to get the objects into a state where the expected feature could be exercised. Of course it's hard to understand the point of a test when there's just so much code. If you see this pattern, then I'd suggest that the code (or at least the test code) needs breaking up a bit. On the other hand, &lt;i&gt;integration&lt;/i&gt; and &lt;i&gt;acceptance&lt;/i&gt; tests that happen to be written using a unit test framework might well be larger.&lt;/p&gt;

&lt;p&gt;One thing I need to explore is whether the naive use of interaction-testing is particularly susceptible to this failing, or whether it happens all the time and we're the only ones who get complained to. I am, however, convinced that the emphasis on mainly using Mocks to substitute external systems (some of which I perpetrated myself in the early days) is a deeply bad idea which pushes teams towards the sort of problem described here.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2008/01/avoid-mega-unit-tests.html' title='Avoid mega unit tests'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=8901297553364329389' title='15 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8901297553364329389'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8901297553364329389'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-6553568752542339527</id><published>2007-12-22T14:13:00.000Z</published><updated>2007-12-22T14:17:02.261Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='news projects'/><title type='text'>Mock objects for Java ME</title><content type='html'>Carl Meijer has asked us to announce his new project...

&lt;blockquote&gt;Yesterday I uploaded a personal project, Hammock, to sourceforge
(&lt;a href="http://sourceforge.net/projects/hammockmocks"&gt;http://sourceforge.net/projects/hammockmocks&lt;/a&gt;).  This a mock object framework for Java ME. Java ME, unfortunately, doesn't support reflection making jMock, EasyMock, etc. unsuitable for use on a mobile device or emulator.  Obviously this makes creating mocks more difficult than with the Java SE mock object frameworks but the distribution includes a utility, HammockMaker, for creating the source for a mock object given a class file (of a non-final class or of an interface).  The framework includes mocks of many of the standard Java ME classes for communications such as HTTP, SMS, OBEX, etc so that one can test without actually hitting a network.  I've used it on three projects at my current employer.&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/12/mock-objects-for-java-me.html' title='Mock objects for Java ME'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=6553568752542339527' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/6553568752542339527'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/6553568752542339527'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-5845619993424176578</id><published>2007-12-04T11:33:00.000Z</published><updated>2007-12-10T14:00:24.242Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><title type='text'>Don't tie down your code, use interfaces</title><content type='html'>&lt;img src="http://www.mockobjects.com/uploaded_images/gulliver.jpeg" alt="Gulliver" style="margin: 0pt 0pt 10px 10px; float: right;" /&gt;
&lt;p&gt;Recently, I was responding to a question on the TDD list and found myself writing this:&lt;/p&gt;
&lt;blockquote&gt;Although there's only one use of the interface, you could think of it as a way of keeping a clean distinction between the naming of different domains (user and persistence). It makes managing package dependencies easier too.&lt;/blockquote&gt;
&lt;p&gt;which is what I've been meaning to say for ages. The reason we're keen on &lt;a href="http://www.mockobjects.com/files/mockrolesnotobjects.pdf"&gt;discovering interfaces&lt;/a&gt; in our code is that we think they're a good way of expressing concepts in a domain.
&lt;/p&gt;
&lt;p&gt;If I'm writing a ring tones store (the video store folded last year) and I need to look up, say, the customers that were active last month, I'll ask a &lt;tt&gt;SalesLedger&lt;/tt&gt; object. So, what type is &lt;tt&gt;SalesLedger&lt;/tt&gt;? If it's a class then my marketing module will have a dependency on whatever persistence framework I use. If my &lt;tt&gt;SalesLedger&lt;/tt&gt; class is clean and delegates to some further persistence type then I've only deferred the problem. I'm importing, directly or indirectly, the persistence packages into my domain code. If I do the same with a few other frameworks (printing, display, network, etc.) then I'll have tied down my domain module with third party dependencies. The module dependency chain looks like this:&lt;/p&gt;

&lt;img src="http://www.mockobjects.com/uploaded_images/class_dependency.png" alt="Class Dependency"/&gt;

&lt;p&gt;There are two problems with this, one obvious and one subtle. The obvious point is that I've raised the risk of inflexible code. One day I'll have to rip out a messy chain of dependencies to get to some code I want to change. Now, because I'm another &lt;a href="http://parlezuml.com/blog/?postid=520"&gt;World's Greatest Software Developer&lt;/a&gt;, I'll be careful not to embed the dependency too deeply and keep my packages clean and layered, but that's  intellectual overhead I could do without. When &lt;tt&gt;SalesLedger&lt;/tt&gt; is an interface, I have a clear distinctions between the domains of marketing and persistence, and I &lt;span style="font-style: italic;"&gt;cannot&lt;/span&gt; let the abstractions leak through. If I do this for all my external dependencies, I can package up my domain code and use it in all sorts of ways I haven't thought of yet. The top-level Application then becomes a matchmaker, introducing all the modules to each other and helping them get started.&lt;/p&gt;

&lt;img src="http://www.mockobjects.com/uploaded_images/interface_dependency.png" alt="Class Dependency"/&gt;

&lt;p&gt;The more subtle issue is that &lt;tt&gt;SalesLedger&lt;/tt&gt;, the interface I use in the body of my code, is in a different domain from the &lt;tt&gt;HibernateLedger&lt;/tt&gt;, a class that implements it (and maybe some other interfaces). The code that uses a &lt;tt&gt;SalesLedger&lt;/tt&gt; is concerned with marketing and payments, the code that uses a &lt;tt&gt;HibernateLedger&lt;/tt&gt; is concerned with setting up connections. There may only be one implementation of an interface, but the two types are addressing different things.&lt;/p&gt;
&lt;p&gt;Is this breaking YAGNI? I don't think so (although there are others that do). I'm not adding features I haven't identified a need for yet. Part of the deal with YAGNI is that I make the code as expressive of my current intentions as I can, and I think I'm expressing the needs of the domain code needs more clearly by limiting its dependency to an interface that defines just the services it needs from other parts of the system.&lt;/p&gt;

&lt;hr /&gt;
&lt;span style="font-size:0;"&gt;n.b. Gulliver image taken from &lt;a href="http://news.bbc.co.uk/1/hi/business/2676711.stm"&gt;news.bbc.co.uk&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/12/interfaces-blindingly-obvious.html' title='Don&apos;t tie down your code, use interfaces'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=5845619993424176578' title='7 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5845619993424176578'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5845619993424176578'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-3430090147438007673</id><published>2007-11-21T14:46:00.001Z</published><updated>2007-11-21T14:48:05.611Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'>MockObjects in Bangalore</title><content type='html'>&lt;p&gt;I'll be presenting a tutorial/workshop/Dojo on TDD with Mock Objects at &lt;a href="http://agileindia.org/stevefreemanonmockobjects"&gt;Agile India in Bangalore&lt;/a&gt; this Sunday. I hope the locals will find the material interesting (and that they give me an easy ride while I struggle with the jet lag :).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/11/mockobjects-in-bangalore.html' title='MockObjects in Bangalore'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=3430090147438007673' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/3430090147438007673'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/3430090147438007673'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-3432632496036002049</id><published>2007-10-19T10:19:00.000+01:00</published><updated>2007-10-19T10:28:57.505+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mocks in action'/><category scheme='http://www.blogger.com/atom/ns#' term='news'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='specification'/><title type='text'>"Testing towards A Specification: A Systematic Approach"</title><content type='html'>&lt;p&gt;Peter Dimov has published his &lt;a href="http://bzr.calitko.org/developers/peter/MasterThesis.pdf"&gt;Master's thesis&lt;/a&gt;. To quote him:&lt;/p&gt;

&lt;blockquote&gt;It is based on Test Driven Development with Mock Objects, hence the focus is on interaction-based testing. I'm introducing the mocking framework CalitkoMocks, which is specially designed to provide a notation for writing tests that can be mapped one-to-one to sequence diagrams. Sequence diagrams are classically used to specify object-oriented software systems, however, it is obvious that just a bunch of diagrams representing individual cases cannot really be regarded as a specification. To address this point, I'm also presenting a few test refactorings which help to extract test scenarios (i.e. generalized test cases), which are more suitable to use as a specification.&lt;/blockquote&gt;

&lt;p&gt;He's implemented a mock framework for C++ that's part of &lt;a href="http://www.calitko.org"&gt;Calitko&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I especially liked his closing remark&lt;/p&gt;

&lt;blockquote&gt;After I drew the diagram corresponding to my test, I decided to try to write a test  corresponding one-to-one to the sequence diagram. The sequence diagram showed the calls to my stub objects but my test didn’t (because the implementation invoked them implicitly). I ended up writing smarter versions of my stubs which eventually evolved into mocks. Though I had already read about mocks at that time, I didn’t quite get it what kind of beasts these were. It was only after I reinvented the mock that I truly understood the concept.&lt;/blockquote&gt;


&lt;p&gt;Perhaps this is a step on the way to addressing &lt;a href="http://www.parlezuml.com/"&gt;Jason Gorman&lt;/a&gt;'s &lt;a href="https://www.blogger.com/comment.g?blogID=34908752&amp;postID=9150604897582101414"&gt;concerns&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/10/testing-towards-specification.html' title='&quot;Testing towards A Specification: A Systematic Approach&quot;'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=3432632496036002049' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/3432632496036002049'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/3432632496036002049'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-5406659771418390835</id><published>2007-10-16T13:29:00.000+01:00</published><updated>2007-10-20T09:07:22.067+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><category scheme='http://www.blogger.com/atom/ns#' term='jmock'/><title type='text'>XpDay London 19/20 November</title><content type='html'>We have a couple of sessions at &lt;a href="http://www.xpday.org"&gt;XpDay London&lt;/a&gt;.

Steve will be giving our Synaesthesia talk on Monday. On Tuesday, Nat, with Romily Cocking, Andy Pols, and Steve (part-time) will be giving an introductory tutorial on TDD with Mocks.

Book soon!&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/10/xpday-london-1920-october.html' title='XpDay London 19/20 November'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=5406659771418390835' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5406659771418390835'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5406659771418390835'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-8037651768494099815</id><published>2007-10-13T11:13:00.000+01:00</published><updated>2007-10-13T11:39:17.685+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mocks in action'/><category scheme='http://www.blogger.com/atom/ns#' term='pictures'/><title type='text'>Mock Throwable</title><content type='html'>&lt;a href="http://www.mockobjects.com/uploaded_images/mock_throwable-774330.jpeg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://www.mockobjects.com/uploaded_images/mock_throwable-774325.jpeg" border="0" alt="" /&gt;&lt;/a&gt;

Yesterday I visited a team at a &lt;a href="http://cyrusinnovation.com/"&gt;Cyrus Innovation&lt;/a&gt; site. They came up with this example. If you can't read it, the writing on the ball says "Throwable". Cute.&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/10/mock-throwable.html' title='Mock Throwable'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=8037651768494099815' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8037651768494099815'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8037651768494099815'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-8839958108970788937</id><published>2007-10-02T00:14:00.000+01:00</published><updated>2007-10-06T16:40:59.652+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='by the way'/><title type='text'>Blogger in German?</title><content type='html'>On a side note, this blog is "powered by Blogger" and I keep getting bits of the UI text in German. Does anyone have any idea what's happening?&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/10/blogger-in-german.html' title='Blogger in German?'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=8839958108970788937' title='2 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8839958108970788937'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8839958108970788937'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-5011553832146327906</id><published>2007-10-01T23:48:00.000+01:00</published><updated>2007-10-02T00:21:00.074+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='domain-specific-language'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><title type='text'>How to talk Mock</title><content type='html'>&lt;p&gt;Brian Marick has posted an &lt;a href="http://www.exampler.com/blog/2007/09/29/talk-you-like-mock/"&gt;interesting proposal&lt;/a&gt; for changing the order of the pieces within a unit test. For example, he suggests moving from &lt;/p&gt;

&lt;pre&gt;def test_checker_normally_checks_network_once 
  checker = testable_checker &lt;em&gt;# creates checker using mocks.&lt;/em&gt;
  @network.should_receive(:ok?).once.with(”url”).and_return(true) 
  checker.check(”url”) 
end&lt;/pre&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;pre&gt;def test_checker_normally_checks_network_once 
  checker = testable_checker 
  during { 
    checker.check(”url”) 
  }.behold! { 
    @network.should_receive(:ok?).once. 
             with(”url”).and_return(true) 
  } 
end&lt;/pre&gt;

&lt;p&gt;which shows what you can do if you have a language with &lt;a href="http://library.readscheme.org/page1.html"&gt;useful constructs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Personally, I've tended to think of stubs and expectations in terms of pre-conditions and post-conditions, so I find the pre-test setup less disturbing&amp;mdash;and I've been doing it so long I don't see it any more. I imagine it's rather like getting used to &lt;code&gt;(+ 1 2)&lt;/code&gt;, which Brian ought to recognise. If I were to have a go, I think I might try to write some like this:&lt;/p&gt;

&lt;pre&gt;during {
  checker.check("url")
}.expect_to_see {
  @network.ok?("url") { returning true }
  @timesink.sleep_for(32.minutes) { 6.times }
  but_not @listener.inform
}&lt;/pre&gt;

&lt;p&gt;It's nice to see someone experimenting with the ideas. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/10/how-to-talk-mock.html' title='How to talk Mock'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=5011553832146327906' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5011553832146327906'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/5011553832146327906'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-4963516390158436615</id><published>2007-08-23T20:13:00.000+01:00</published><updated>2007-08-23T20:32:36.536+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'>GTAC. Google Test Automation Conference</title><content type='html'>&lt;p&gt;I'm at Google's &lt;a href="http://googletesting.blogspot.com/search/label/GTAC"&gt;Test Automation Conference&lt;/a&gt; in New York City (my old stamping ground from the '80's) and so far Mocks have been doing quite well. We had several mentions on his slides from Patric Copeland (Director of QA at Google).&lt;/p&gt;
&lt;p&gt;There was also a presentation from Matt Heuser and Sean McMillan, "Examining Interaction-Based testing". I admit I feared a hatchet job but, actually, they presented a very balanced view. They had some good examples of Interaction Testing gone wrong, such as mocking out production code and not writing integration tests. They also pointed out the benefits of using TDD with mocks, including ending up with  good code quality statistics implying good maintainability.&lt;/p&gt;
&lt;p&gt;The one comment I had on the talk was to de-emphasise use of mocks to speed up unit test runs by mocking external (slow) resources. Our preference is to use mocks within our domain code but to try to write focussed integration tests at the outer boundaries of the system.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/08/gtac-google-test-automation-conference.html' title='GTAC. Google Test Automation Conference'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=4963516390158436615' title='3 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/4963516390158436615'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/4963516390158436615'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-9150604897582101414</id><published>2007-08-20T19:34:00.000+01:00</published><updated>2007-08-26T15:48:07.782+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>We don't need no stinking interfaces</title><content type='html'>&lt;p&gt;There's been another round of anti-Dependency Injection chatter in the blogsphere, so here we go again. Ayende's done a pretty good job of &lt;a href="http://ayende.com/Blog/archive/2007/08/18/Dependency-Injection-IAmDonQuixote.aspx"&gt;defending his response&lt;/a&gt; to the &lt;a href="http://scruffylookingcatherder.com/archive/2007/08/16/tilting-at-windmills.aspx"&gt;original posting&lt;/a&gt;. The arguments are the same as usual: we don't see why we should change our design just to make it testable. I would like to add a few comments to this round.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static factories and the like are still dependencies, just implicit. Instead of making the dependencies clear in the code, so you can set up an object once and then just use it, statics force you to package up a load of hidden references with your class that aren't relevant after instantiation&lt;/li&gt;

&lt;li&gt;I don't go around exposing private features all over the place. I expose the parts that need exposing because they express a relationship with a &lt;a href="http://www.mockobjects.com/2006/10/different-kinds-of-collaborators.html"&gt;collaborator&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;As an author on the original papers, I resent quotes like
&lt;blockquote&gt;I wonder if this is a defensive reaction because the authors of the examples don’t want to have to justify making you fundamentally alter your coding habits and re-write all of your existing code just so that you can use their pet objects.&lt;/blockquote&gt;
I'm used to being disagreed with over this technique, but this is a new one on me. Our approach to design has a long and very respectable history. If you're not aware of its roots, then maybe you &lt;em&gt;should&lt;/em&gt; alter your coding habits.&lt;/li&gt;

&lt;li&gt;I could do without &lt;a href="http://scruffylookingcatherder.com/archive/2007/08/16/tilting-at-windmills.aspx#306"&gt;some of the language&lt;/a&gt;, such as
&lt;blockquote&gt;"The emperor is naked" and you see it.&lt;/blockquote&gt;
and
&lt;blockquote&gt;Take a look at what people are asking for on the xxMocks forums and the yahoo test-driven group and you will see how every problem that the tool can't solve is actually a design smell. Pragmatic development teams don't believe this anymore.&lt;/blockquote&gt;
like we don't care about shipping reliable and effective systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One good thing this episode shows is that there are plenty of people who understand the issues and are prepared to engage. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/08/we-dont-need-no-stinking-interfaces.html' title='We don&apos;t need no stinking interfaces'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=9150604897582101414' title='7 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/9150604897582101414'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/9150604897582101414'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-2430411814568030499</id><published>2007-08-20T17:26:00.000+01:00</published><updated>2007-08-20T17:44:23.993+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mocks in action'/><title type='text'>AtomicObject use mocks for Embedded C</title><content type='html'>&lt;p&gt;At &lt;a href="www.agile2007.org"&gt;Agile 2007&lt;/a&gt; I chaired an &lt;a hrerf="http://www.agile2007.org/index.php?page=sub/&amp;id=757"&gt;experience report&lt;/a&gt; session which had an elegant paper from &lt;a href="www.atomicobject.com"&gt;AtomicObject&lt;/a&gt; on their approach to developing code for embdedded systems in C. The relevant bit for this blog is their use of interaction testing.&lt;/p&gt;
&lt;p&gt;To make up for the lack of reflection in C, they defined conventions for their header files and wrote Ruby scripts in &lt;a href="http://rake.rubyforge.org/"&gt;Rake&lt;/a&gt; to generate mocks and link in the right code for the unit tests.&lt;/p&gt;
&lt;p&gt;Why did they go to all this trouble? In their words&lt;/p&gt;
&lt;blockquote&gt;our mocks revealed that some of the code was making calls it shouldn't have been&lt;/blockquote&gt;
&lt;blockquote&gt;The mocks also helped us enforce single responsibility. Whenever the tests for a piece of code got too complicated, we could usually find a good way to break some of the complexity out into another module.&lt;/blockquote&gt;
&lt;p&gt;and from the presentation:&lt;/p&gt;
&lt;blockquote&gt;Interaction-based testing made tests easier to write and less brittle&lt;/blockquote&gt;
&lt;p&gt;It's nice to see the ideas port to a significantly different environment&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/08/atomicobject-use-mocks-for-embedded-c.html' title='AtomicObject use mocks for Embedded C'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=2430411814568030499' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2430411814568030499'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2430411814568030499'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-802414132354089627</id><published>2007-07-04T16:56:00.000+01:00</published><updated>2007-07-04T17:55:56.638+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='process'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><title type='text'>Start with a working system</title><content type='html'>&lt;p&gt;Image we've just been commissioned to build a system, we have 30-inch monitors, we have the Customer in the room, we've prioritised some stories, now let's write a unit test! Well, maybe not yet. Our first test should be an attempt at something end-to-end that exercises a visibly useful feature (even if it's really, really tiny). To make this test pass, we'll need a Walking Skeleton, an absolutely minimal sliver of the whole system that actually works. To make the Walking Skeleton work, we'll have to think about the structure of the system, including build and deployment, which will help us flush out a whole Sackful&lt;sup&gt;1&lt;/sup&gt; of project risk: our chosen messaging system doesn't work on our chosen platform, we need 4 weeks notice and 8 signatures to make a change to production, the target PCs only have 640K of RAM, and so on.&lt;/p&gt;

&lt;p&gt;As a rule, we only discover this sort of issue when we actually try it, which is why we like to start with a build and deploy script, and &lt;em&gt;then&lt;/em&gt; figure out what to put in it. We also prefer deploying as close to production as possible, since each step in the end-to-end journey brings its own challenges. This approach means we find the blockages at the start of the project, when we still have time to fix them, rather than at the end. In practice, of course, sometimes these steps take so long to implement that we start with a shadow system to stand in for our current interpretation of the real thing. But this is only a stop-gap, a temporary patch to allow us to make progress, it's not an acceptable end solution.&lt;/p&gt;

&lt;p&gt;We need to make the point more strongly that unit-level testing (even using mocks!) should take place within the context of higher-level tests that set the direction for the current slice of development. The higher-level tests keep us focussed on what we need to implement next and keep us honest about what is working.&lt;p&gt;

&lt;p&gt;&lt;em&gt;1) that's a level-2 Sackful, as defined in the PMBOK.&lt;/em&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/07/start-with-working-system.html' title='Start with a working system'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=802414132354089627' title='1 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/802414132354089627'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/802414132354089627'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-2312430860880947544</id><published>2007-07-04T11:46:00.000+01:00</published><updated>2007-07-04T16:02:02.134+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='domain-specific-language'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>What does "easy" really mean?</title><content type='html'>&lt;p&gt;Steve's recent post about the perceived conflict between Testability and Design included this quote from a user of TypeMock:&lt;/p&gt;

&lt;blockquote&gt;The key benefit we get from TypeMock is having the ability to fully unit-test the code without impacting the API design. [...] For us, the API is part of the deliverable. We need to make it fairly easy to consume and can't have the architecture of the solution overshadow the usability of the API.&lt;/blockquote&gt;

&lt;p&gt;The crux of the issue is in the words "easy to consume". What does that mean? Easy to learn? Or easy to adapt to new, unanticipated situations.&lt;/p&gt;

&lt;p&gt;For example, many developers find the &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/io/package-summary.html"&gt;java.io &lt;/a&gt; API complicated. This is how to open a file for reading:&lt;/p&gt;

&lt;pre class="Java Source"&gt;Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));&lt;/pre&gt;

&lt;p&gt;The equivalents C or Python are much shorter, in Python:&lt;/p&gt;

&lt;pre class="Python Source"&gt;reader = open("input.txt")&lt;/pre&gt;

&lt;p&gt;The Java version does, however, have a point. Is use of the &lt;a href="http://en.wikipedia.org/wiki/Decorator_pattern"&gt;Decorator&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern"&gt;Chain of Responsibility&lt;/a&gt; patterns makes it easy to apply in different situations and adapt different underlying transports to the &lt;code&gt;java.io&lt;/code&gt; stream model. In the C approach. different implementations are buried in the runtime, so you have to go to a different mechanism to try anything new.&lt;/p&gt;

&lt;p&gt;TDD with mock objects drives an object-oriented design towards one like the java.io API. The design process focuses on discovering common patterns of communication between objects. The end-to-end system behaviour is defined by composing objects instead of writing algorithmic code. That makes code more malleable by experienced programmers but, arguably, makes it harder to learn for newcomers to the codebase or to object-oriented programming itself.&lt;/p&gt;

&lt;p&gt;The problem can be addressed by layering expressive APIs that support common operations above the flexible, object-oriented core.  A simple API is easy to learn but allows the programmer to drill down to the flexible core when new &lt;em&gt;unexpected&lt;/em&gt; situations arise.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.jmock.org/"&gt;JMock&lt;/a&gt; itself follows this model.  The core is an object-oriented framework for representing and checking expectations.  This framework is flexible and extensible. You can create and compose objects to represent and test all sorts of expectations. This level of code, however, is too fine-grained to express the intent of a test. It's like trying to figure out what's for dinner from reading the recipes. That's why we also wrote a high-level API that is closer to the programmer's problem domain. It makes it easy for us to write readable code to set up framework objects &lt;em&gt;and&lt;/em&gt; we still have the extension points we need when we need a new feature &amp;mdash; &lt;em&gt;and&lt;/em&gt; we can test jMock without manipulating bytecodes.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/06/what-does-easy-really-mean.html' title='What does &quot;easy&quot; really mean?'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=2312430860880947544' title='6 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2312430860880947544'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/2312430860880947544'/><author><name>Nat Pryce</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-1945823248006603234</id><published>2007-06-15T13:52:00.000+01:00</published><updated>2007-06-15T17:26:18.612+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'>Making a point in IEEE Software</title><content type='html'>&lt;img style="float:right; margin:0 0 10px 10px;" src="http://www.mockobjects.com/uploaded_images/soft_01-721368.gif" border="0" alt="IEEE Software" /&gt;

We've had a position published (with &lt;a href="http://www.industriallogic.com/company/coaches/index.html"&gt;Joshua Kerievsky&lt;/a&gt; on the other side) in the May/June issue of &lt;a href="http://www.computer.org/portal/site/software/"&gt;IEEE Software&lt;/a&gt;. To quote the abstract:

&lt;blockquote&gt;Point Argument: &lt;em&gt;Mock Objects: Find Out Who Your Friends Are&lt;/em&gt;, by Steve Freeman and Nat Pryce. Mock objects help guide object-oriented programming by concentrating on what objects do, no what they are. Counterpoint Argument: &lt;em&gt;TDD: Don't Much It Up with Too Many Mocks&lt;/em&gt;, by Joshua Kerievsky. Routinely test-driving code with mock objects leads to premature object composition, hard-to-read and fragile code, and lost time. This department is part of a special issue on test-driven development.&lt;/blockquote&gt;

It looks like you have to pay (or get a copy of the magazine) to get the content. I'll ask if we can post our chunk. (thanks to the people who pointed out that you can download a &lt;em&gt;different&lt;/em&gt; issue of the journal).&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/06/making-point-in-ieee-software.html' title='Making a point in IEEE Software'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=1945823248006603234' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/1945823248006603234'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/1945823248006603234'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-1097079396076182186</id><published>2007-05-23T12:23:00.000+01:00</published><updated>2007-05-23T12:31:36.024+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='listening to the tests'/><title type='text'>Test Smell: Too many expectations</title><content type='html'>&lt;a href="http://www.mockobjects.com/labels/listening%20to%20the%20tests.html"&gt;&lt;img style="float:left; margin:10px 10px 10px 0;" src="http://www.mockobjects.com/uploaded_images/synaesthesia_thumb-713092.png" border="0" alt="Synaesthesia" /&gt;&lt;/a&gt;

&lt;p&gt;When a test has too many expectations it's hard to see what's important, what's really under test. For example, here's a test:&lt;/p&gt;

&lt;pre style="margin-top: 50px;"&gt;@Test public void decidesCasesWhenFirstPartyIsReady() {
  context.checking(new Expectations(){{
    one(firstPart).isReady(); will(returnValue(true));
    one(organiser).getAdjudicator(); will(returnValue(adjudicator));
    one(adjudicator).findCase(firstParty, issue); will(returnValue(case));
    one(thirdParty).proceedWith(case);
  }});
  
  claimsProcessor.adjudicateIfReady(thirdParty, issue);
}&lt;/pre&gt;

&lt;p&gt;that might be implemented like this:&lt;/p&gt;

&lt;pre&gt;public void adjudicateIfReady(ThirdParty thirdParty, Issue issue) {
  if (firstParty.isReady()) {
    Adjudicator adjudicator = organisation.getAdjudicator();
    Case case = adjudicator.findCase(firstParty, issue);
    thirdParty.proceedWith(case);
  } else{
    thirdParty.adjourn();
  }
}&lt;/pre&gt;

&lt;p&gt;What makes the test hard to read is that everything is an expectation, so everything seems to be equally important. I can't tell what's significant and what's just there to get me through the test.&lt;/p&gt;

&lt;p&gt;In fact, if I look at all the methods I call, there are only two that have any side effects outside this class: &lt;code&gt;thirdParty.proceedWith()&lt;/code&gt; and &lt;code&gt;thirdParty.adjourn()&lt;/code&gt;. It would be an error to call these more than once. All the other methods are queries, I can call &lt;code&gt;organisation.getAdjudicator()&lt;/code&gt; repeatedly without breaking any behaviour. &lt;code&gt;adjudicator.findCase()&lt;/code&gt; might go either way, but it happens to be a lookup so it has no side effects.&lt;/p&gt;

&lt;p&gt;I can make my intentions clearer by distinguishing between &lt;em&gt;Stubs&lt;/em&gt;, simulations of real behaviour that help me get my test to pass, and &lt;em&gt;Expectations&lt;/em&gt;, assertions I want to make about how my object interacts with its neighbours. Reworking my test, I get:&lt;/p&gt;

&lt;pre&gt;@Test public void decidesCasesWhenFirstPartyIsReady() {
  context.checking(new Expectations(){{
    &lt;em&gt;allowing&lt;/em&gt;(firstPart).isReady(); will(returnValue(true));
    &lt;em&gt;allowing&lt;/em&gt;(organiser).getAdjudicator(); will(returnValue(adjudicator));
    &lt;em&gt;allowing&lt;/em&gt;(adjudicator).findCase(firstParty, issue); will(returnValue(case));
    
    one(thirdParty).proceedWith(case);
  }});
  
  claimsProcessor.adjudicateIfReady(thirdParty, issue);
}&lt;/pre&gt;

&lt;p&gt;which is explicit about how I expect my object to change the world.&lt;/p&gt;

&lt;h3&gt;Stub queries, mock actions&lt;/h3&gt;

&lt;p&gt;For the more formally minded, you might want to think (very, very loosely) of Stubs as pre-conditions and Expectations as post-conditions. The test now says that &lt;em&gt;given&lt;/em&gt; the state described in the Stubs, the events described by the Expectations &lt;em&gt;should&lt;/em&gt; have happened. Once I've sorted out which calls are Stubs, I can usually move some of them into common setup code, making the tests clearer still:&lt;/p&gt;

&lt;pre&gt;@Test public void decidesCasesWhenFirstPartyIsReady() {
  context.checking(new Expectations(){{
    &lt;em&gt;allowing&lt;/em&gt;(firstParty).isReady(); will(returnValue(true));
    
    one(thirdParty).proceedWith(case);
  }});
  
  claimsProcessor.adjudicateIfReady(thirdParty, issue);
}&lt;/pre&gt;

&lt;p&gt;It is, of course, possible that all the methods calls are actions. In which case, either I just have a complicated domain and there's not much I can do to simplify it or, more likely, there are some intermediate concepts in there that need to be extracted into objects.&lt;/p&gt;

&lt;p&gt;Clearly, when I'm thinking about the whole system, I can't ignore implementation issues such as the cost of database queries, but that's not relevant &lt;em&gt;at this point&lt;/em&gt;. What matters now is that I have tests and code that clearly express my intentions.&lt;/p&gt;

&lt;p style="margin-left: 3em;"&gt;On a side note, this is why I'm not keen on an expectation syntax like this: &lt;code&gt;expect(firstParty.isReady()).stubReturn(true)&lt;/code&gt;. I find the leading "expect" confusing, when my intention is to stub.&lt;/p&gt;

&lt;h3&gt;Special bonus prize&lt;/h3&gt;
&lt;p&gt;I always have problems coming up with good examples. There's actually a better improvement to this code, which is to notice that that I've pulled out a chain of objects to get to the &lt;code&gt;case&lt;/code&gt; object, exposing dependencies that aren't relevant here. What I &lt;em&gt;should&lt;/em&gt; have done is told the nearest object to do the work for me, like this:&lt;/p&gt;

&lt;pre&gt;public void adjudicateIfReady(ThirdParty thirdParty, Issue issue) {
  if (firstParty.isReady()) {
    organisation.adjudicateBetween(firstParty, thirdParty, issue);
  } else{
    thirdParty.adjourn();
  }
}&lt;/pre&gt;

&lt;p&gt;or, possibly,&lt;/p&gt;

&lt;pre&gt;public void adjudicateIfReady(ThirdParty thirdParty, Issue issue) {
  if (firstParty.isReady()) {
    thirdParty.startAdjudication(organisation, firstParty, issue);
  } else{
    thirdParty.adjourn();
  }
}&lt;/pre&gt;

&lt;p&gt;which looks more balanced. If you spotted this then I award you a Moment of Smugness&amp;trade; to be exercised at your convenience.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/test-smell-too-many-expectations.html' title='Test Smell: Too many expectations'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=1097079396076182186' title='2 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/1097079396076182186'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/1097079396076182186'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-4923056886791860808</id><published>2007-05-21T20:03:00.000+01:00</published><updated>2007-05-21T22:20:01.548+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='domain-specific-language'/><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'>Apache Camel</title><content type='html'>The &lt;a href="http://www.apache.org"&gt;Apache&lt;/a&gt; &lt;a href="http://activemq.apache.org"&gt;ActiveMQ project&lt;/a&gt; has recently released &lt;a href="http://activemq.apache.org/camel"&gt;Camel&lt;/a&gt;, a rule based routing and mediation engine for building &lt;a href="http://activemq.apache.org/camel/enterprise-integration-patterns.html"&gt;enterprise integration&lt;/a&gt; systems.  Camel provides a &lt;a href="http://activemq.apache.org/camel/dsl.html"&gt;DSL-style Java API&lt;/a&gt;, inspired by &lt;a href="http://www.jmock.org"&gt;jMock&lt;/a&gt; and &lt;a href="https://lift.dev.java.net/"&gt;LiFT&lt;/a&gt;, to specify rules for routing, transforming and monitoring messages and you can use &lt;a href="http://activemq.apache.org/camel/mock.html"&gt;mock message receivers&lt;/a&gt; to describe and verify expected message flows in tests.&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/apache-camel.html' title='Apache Camel'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=4923056886791860808' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/4923056886791860808'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/4923056886791860808'/><author><name>Nat Pryce</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-975404129210113116</id><published>2007-05-20T21:59:00.000+01:00</published><updated>2007-05-20T22:44:17.775+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>Testability vs. Design (again)</title><content type='html'>&lt;p&gt;I'm sure TypeMock is a fine piece of software, but I just cannot agree with their notion that API design and testability are in conflict. Their new &lt;a href="http://www.elilopian.com/2007/05/16/typemock-case-study-in-corillian/"&gt;case study&lt;/a&gt; includes the statement:&lt;/p&gt;
&lt;blockquote&gt;The key benefit we get from TypeMock is having the ability to fully unit-test the code without impacting the API design. [...] For us, the API is part of the deliverable. We need to make it fairly easy to consume and can't have the architecture of the solution overshadow the usability of the API.&lt;/blockquote&gt;

&lt;p&gt;In the other corner we have Michael Feathers who has been running a tutorial called &lt;a href="http://www.objectmentor.com/resources/articles/as_if_unit_testing_mattered.pdf"&gt;API Design as if Unit Testing mattered&lt;/a&gt;. Michael is one of the most interesting people I know on the Agile circuit, although he doesn't make a fuss about it. To quote him:&lt;/p&gt;

&lt;blockquote&gt;Have you ever tried to write a unit test for a class that uses an external API? An API that is not mockable? Testing seems to be the last thing on our minds when we design APIs. It isn't that we don't test our APIs, we just don't make it easy to test code that uses our APIs.&lt;/blockquote&gt;

&lt;p&gt;His point is that, for library designers, even writing tests for your API is not enough to produce something that's really useable, you have to try writing tests for the code that will use your API. Or, as &lt;a href="http://blogs.msdn.com/mpuleio/pages/design-as-if-testing-matters.aspx"&gt;Michael Puleio&lt;/a&gt; wrote, &lt;/p&gt;

&lt;blockquote&gt;If your API is hard to unit test, how in the heck are your users going to be able to use it?&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/testability-vs-design-again.html' title='Testability vs. Design (again)'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=975404129210113116' title='7 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/975404129210113116'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/975404129210113116'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-941742107366941161</id><published>2007-05-14T14:35:00.000+01:00</published><updated>2007-05-14T15:30:53.856+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='listening to the tests'/><title type='text'>What the tests will tell you</title><content type='html'>&lt;a href="http://www.mockobjects.com/labels/listening%20to%20the%20tests.html"&gt;&lt;img style="float:left; margin:10px 10px 10px 0;" src="http://www.mockobjects.com/uploaded_images/synaesthesia_thumb-713092.png" border="0" alt="Synaesthesia" /&gt;&lt;/a&gt;

&lt;p&gt;We've found these benefits from learning to Listen to the Test Smells.&lt;/p&gt;

&lt;p style="margin-top: 70px;"&gt; 
&lt;dl&gt;
  &lt;dt&gt;Keeping knowledge local&lt;/dt&gt;
  &lt;dd&gt;Some of the test smells we've identified, such as &lt;a href="http://www.mockobjects.com/2007/04/test-smell-i-need-to-mock-object-i-cant.html"&gt;needing magic to create mocks&lt;/a&gt;, are to do with knowledge leaking between components. If I can keep knowledge local to an object, either internal or passed in, then its implementation is independent of its context. I can safely move it wherever I like. Do this consistently and I can build an application as a web of communicating objects.&lt;/dd&gt;
  &lt;dt&gt;If it's explicit I can name it&lt;/dt&gt;
  &lt;dd&gt;This is why I don't like &lt;a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html"&gt;mocking concrete classes&lt;/a&gt;, I like to have names for the relationships between objects as well the objects themselves. As the legends say, if I have something's true name then I can control it. If I can see it, I have more chance of finding other uses and so reducing duplication.&lt;/dd&gt;
  &lt;dt&gt;More names mean more domain information&lt;/dt&gt;
  &lt;dd&gt;I find that when we emphasise how objects &lt;em&gt;communicate&lt;/em&gt;, rather than what they &lt;em&gt;are&lt;/em&gt;, I end up with types and roles defined more in terms of the domain than of the implementation. I think this might be because I have more, smaller abstractions which gets me a further away from the underlying language. Somehow I seem to get more domain vocabulary into the code.&lt;/dd&gt;
  &lt;dt&gt;Pass behaviour rather than data&lt;/dt&gt;
  &lt;dd&gt;I find that TDD with mocks encourages me to write objects that tell each other what to do, rather then requesting and manipulating values. Applied consistently, I end up with a coding style where I pass behaviour (in listeners and callbacks) from the higher levels of the code to the data, rather than pulling data up through the stack. It's an unusual style in the Java/C# world, but I find that we get better encapsulation and clearer abstractions because I have to clarify what the pieces will do, not just what values they hold.
  &lt;/dd&gt;
&lt;/dl&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/what-tests-will-tell-you.html' title='What the tests will tell you'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=941742107366941161' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/941742107366941161'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/941742107366941161'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-116068810034967604</id><published>2007-05-09T13:00:00.000+01:00</published><updated>2007-05-09T16:37:59.233+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='listening to the tests'/><title type='text'>Object Collaboration Stereotypes</title><content type='html'>&lt;a href="http://www.mockobjects.com/labels/listening%20to%20the%20tests.html"&gt;&lt;img style="float:left; margin:10px 10px 10px 0;" src="http://www.mockobjects.com/uploaded_images/synaesthesia_thumb-713092.png" border="0" alt="Synaesthesia" /&gt;&lt;/a&gt;

&lt;p&gt;Another diagnosis for a &lt;a href="http://www.mockobjects.com/2007/04/test-smell-bloated-constructor.html"&gt;Bloated Constructor&lt;/a&gt; might be that not all of the arguments are &lt;em&gt;dependencies&lt;/em&gt;, services that &lt;em&gt;must&lt;/em&gt; be passed to the object before it can do its job.  Other arguments might be more to do with structuring the implementation of the object or varying its behaviour to suit its neighbours. To help me think about this distinction, I've found it useful to categorise the peers of an object into four stereotypes:&lt;/p&gt;

&lt;ul style="list-style: none;"&gt;
  &lt;li&gt;&lt;em&gt;Dependencies&lt;/em&gt; are services that the object needs from its environment so that it can fulfil its responsibilities.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Notifications&lt;/em&gt; are other parts of the system that need to know when the object changes state or performs an action.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Policies&lt;/em&gt; are objects that tweak or adapt the object's behaviour to the needs of the system.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Parts&lt;/em&gt; are components in the implementation that are not controlled from outside the object after being set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dependencies must be passed in through the constructor. An object needs the system to provide implementations of its dependencies to function at all, so there's no point in creating an instance until they're available. Partially creating an object and then finishing it off by setting properties is risky and brittle because the programmer has to know whether all the dependencies have been set.  As &lt;a href="http://www.starwars.com/databank/character/yoda/"&gt;Yoda&lt;/a&gt; said, "New, or new not. There is no try."&lt;/p&gt;


&lt;p&gt;Other types of peer can be passed to the constructor as a convenience but, if the list is becoming too long, they can also be initialised to safe defaults and overridden later (one way to distinguish the two is that there are no safe defaults for a Dependency). Policies and Parts can be initialised to commonly used cases, and collections of Parts can be initialised as empty. I can then add setters and add/remove methods to the class to allow the object's clients to configure it. Similarly, Notifications can be implemented as events. Unicast events can be initialised with a &lt;a href="http://www.c2.com/cgi/wiki?NullObject"&gt;null implementation&lt;/a&gt; of the listener interface, and multicast events can be initialised with an empty collection of listeners. I always create a valid object, and I also have the hooks I need for testing.&lt;/p&gt;

&lt;h3&gt;A high speed example&lt;/h3&gt;

&lt;p&gt;Here's an example, it's probably not quite bad enough to need fixing, but it'll do to make the point. The application is a Formula 1 racing game, players can try out different configurations of car and driving style to see which one wins. A &lt;code&gt;RacingCar&lt;/code&gt; represents a competitor within a race. &lt;/p&gt;

&lt;pre class="Java Source"&gt;public class RacingCar {
  private final Track track;
  private Tyres tyres;
  private Suspension suspension;
  private Wing frontWing;
  private Wing backWing;
  private double fuelLoad;
  private CarListener listener;
  private DrivingStrategy driver;

  public RacingCar(Track track, DrivingStrategy driver, 
                  Tyres tyres, Suspension suspension, 
                  Wing frontWing, Wing backWing, double fuelLoad,
                  CarListener listener)
  {
    this.track = track;
    this.driver = driver;
    this.tyres = tyres;
    this.suspension = suspension;
    this.frontWing = frontWing;
    this.backWing = backWing;
    this.fuelLoad = fuelLoad;
    this.listener = listener;
  }
}&lt;/pre&gt;
    
&lt;p&gt;It turns out that the &lt;code&gt;track&lt;/code&gt; is the only Dependency of a &lt;code&gt;RacingCar&lt;/code&gt;, the hint is that it's the only field that's final. The &lt;code&gt;driver&lt;/code&gt; is a Policy, the &lt;code&gt;listener&lt;/code&gt; is a Notification, and the rest are Parts; all of these can be modified by the user before or during the race. Here's a reworked constructor: &lt;/p&gt;

&lt;pre class="Java Source"&gt;public class RacingCar {
  private final Track track;

  private DrivingStrategy driver = DriverTypes.borderlineAggressiveDriving();
  private Tyres tyres = TyreTypes.mediumSlicks();
  private Suspension suspension = SuspensionTypes.mediumStiffness();;
  private Wing frontWing = WingTypes.mediumDownforce();
  private Wing backWing = WingTypes.mediumDownforce();
  private double fuelLoad = 0.5;

  private CarListener listener = CarListener.NONE;

  public RacingCar(Track track) {
    this.track = track;
  }
    
  public void setSuspension(Suspension suspension) { &amp;hellip;
  public void setTyres(Tyres tyres) {  &amp;hellip;
  public void setEngine(Engine engine) {  &amp;hellip;
   
  public void setListener(CarListener listener) {  &amp;hellip;
  &amp;hellip;
}&lt;/pre&gt;

&lt;p&gt;Now I've initialised the peers to most common defaults, the user can then configure them through the user interface. I've initialised the &lt;code&gt;listener&lt;/code&gt; to a null implementation, again this can be changed later by the object's environment.&lt;/p&gt;

&lt;h3&gt;A matter of taste&lt;/h3&gt;

&lt;p&gt;These stereotypes are only heuristics to help me think about the design, not hard rules, so I don't get obsessed with finding just the right classification of an object's peers. What matters most is the context in which I'm developing the object, my mental model of the domain. For example, an auditing log might be a Dependency, since it's a legal requirement for the business, or a Notification, since the object will otherwise function without it. Policies belong to the environment and can usually be constants, since they're often immutable and so don't need to be instantiated more than once. Parts belong to the object and usually cannot be stateless, so they need a new instance. For example, in my Racing Car, &lt;code&gt;tyres&lt;/code&gt; might be a Policy if &lt;code&gt;TyreTypes.mediumSlicks()&lt;/code&gt; describes only how the choice of tyre affects the car's handling, but a Part if it stores mutable values such as air pressure and wear.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2006/10/different-kinds-of-collaborators.html' title='Object Collaboration Stereotypes'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=116068810034967604' title='2 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/116068810034967604'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/116068810034967604'/><author><name>Nat Pryce</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-6582760582974605293</id><published>2007-05-08T14:10:00.000+01:00</published><updated>2007-05-08T14:27:58.842+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='explanation'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='testability'/><title type='text'>Mocking classes challenge</title><content type='html'>&lt;p&gt;I'm in a communcation quandry. I'm either missing a point or can't explain something, or both.&lt;/p&gt;

&lt;p&gt;I &lt;a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html"&gt;really don't like mocking classes&lt;/a&gt;, except where I'm trying to cut a seam in some legacy code, but &lt;a href="http://colinjack.blogspot.com/2006/08/typemock-helps-improve-your-designs.html"&gt;other people&lt;/a&gt; disagree.&lt;/p&gt;

&lt;p&gt;Can someone post or send me an example of code where interaction-testing with interfaces doesn't work well? Thanks&lt;/p&gt;

&lt;p&gt;Contact me at &lt;tt&gt;mockexample&amp;nbsp;&lt;em&gt;theAtSymbol&lt;/em&gt;&amp;nbsp;m3p&amp;nbsp;&lt;em&gt;theDotCharacter&lt;/em&gt;&amp;nbsp;co &lt;em&gt;anotherDotHere&lt;/em&gt;&amp;nbsp;uk&lt;/tt&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/mocking-classes-challenge.html' title='Mocking classes challenge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=6582760582974605293' title='3 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/6582760582974605293'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/6582760582974605293'/><author><name>Steve Freeman</name></author></entry><entry><id>tag:blogger.com,1999:blog-34908752.post-8959385186517000269</id><published>2007-05-02T17:12:00.000+01:00</published><updated>2007-05-02T17:14:52.299+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='listening to the tests'/><title type='text'>Cross-referencing Code Smells</title><content type='html'>While we've been writing up our &lt;a href="http://www.mockobjects.com/labels/listening%20to%20the%20tests.html"&gt;Test Smells&lt;/a&gt;, here's a good summary of some &lt;a href="http://www.codinghorror.com/blog/archives/000589.html"&gt;Code Smells&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://technorati.com/claim/e3dy57vh3k" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;/div&gt;</content><link rel='alternate' type='text/html' href='http://www.mockobjects.com/2007/05/cross-referencing-code-smells.html' title='Cross-referencing Code Smells'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34908752&amp;postID=8959385186517000269' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.mockobjects.com/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8959385186517000269'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34908752/posts/default/8959385186517000269'/><author><name>Steve Freeman</name></author></entry></feed>