<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Jak Charlton - Insane World : Mocking</title><link>http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx</link><description>Tags: Mocking</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Make It Easy To Refactor</title><link>http://devlicio.us/blogs/casey/archive/2009/09/21/make-it-easy-to-refactor.aspx</link><pubDate>Mon, 21 Sep 2009 15:17:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:51578</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=51578</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=51578</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2009/09/21/make-it-easy-to-refactor.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m currently looking at a code base that could do with some refactoring, overall it&amp;#39;s a pretty good code base, and the test coverage is pretty good too. But looking through it gave me some ideas on what makes a code base tricky to safely refactor. Here are some tips to make sure your code is in a good state to be refactored with safety and confidence.&lt;/p&gt;
&lt;h3&gt;Provide Good Test Names&lt;/h3&gt;
&lt;p&gt;Test methods should have good, meaningful names; this is of course exactly the same as all code - naming is very important to give context and meaning. I am looking at a lot of tests that make sense to the original developer, and within reason make sense to me, but they do not properly describe what the test tries to do and what it expects.&lt;/p&gt;
&lt;p&gt;A test named &amp;quot;ValidHardware()&amp;quot; is less than ideal for telling me the intent of the test.&amp;nbsp; If the method had been correctly named it would have been called:&lt;/p&gt;
&lt;p style="PADDING-LEFT:30px;"&gt;ensure_that_hardware_detector_returns_true_when_valid_hardware_is_present()&lt;/p&gt;
&lt;p&gt;Now you tell me, which is easier to understand? And which is going to give me more confidence in refactoring that hardware detector?&lt;/p&gt;
&lt;h3&gt;Make Sure Variables Are Well Named&lt;/h3&gt;
&lt;p&gt;Probably blindingly obvious given the above section, but if you use poor variable names, I am probably going to waste a lot of time trying to figure out exactly which thing is which, and worse still, I am probably going to miss subtle bugs.&lt;/p&gt;
&lt;h3&gt;Cover The Right Things&lt;/h3&gt;
&lt;p&gt;Beware of high coverage that does not actually test either all the aspects of a component, or that makes a lot of assumptions. &lt;/p&gt;
&lt;p&gt;Getting 100% coverage is likely to be impossible, and probably your return on investment over 75% is going to be low, but don&amp;#39;t achieve the 75% by testing the trivial and easy to test things only - it&amp;#39;s going to be those tricky to test components that will cause most bugs when refactoring.&lt;/p&gt;
&lt;p&gt;If something is tricky to test, perhaps you have the wrong level of abstraction applied, or perhaps the test is trying to tell you something. Skipping it and going for some simpler tests may pay off in the short term, but in the long term will hurt you.&lt;/p&gt;
&lt;h3&gt;Avoid Fragile Tests&lt;/h3&gt;
&lt;p&gt;There is a lot of debate between the &amp;quot;classicist and mockist schools&amp;quot; about what to test, and personally I veer towards state based testing for most components - but regardless of where your personal impulses lie, avoid creating fragile tests. Any test that is likely to break with trivial refactoring could be considered fragile, and those tests are going to cost you a lot of time and cause many potential bugs when refactoring.&lt;/p&gt;
&lt;p&gt;One of the main causes of fragile tests are an overreliance on mocks, and specifically using mocks over stubs. &amp;nbsp;By all means mock where necessary, but try to limit mock usage to very specific test cases, and try to favour stubs over mocks and favour &amp;quot;Setup.ResultFor&amp;quot; over &amp;quot;Expect.Call&amp;quot; type semantics.&lt;/p&gt;
&lt;h3&gt;Avoid [Setup] and [Teardown]&lt;/h3&gt;
&lt;p&gt;Yes, I know they make it easier to create lots of similar tests, but they make your tests fragile and interdependent.&lt;/p&gt;
&lt;p&gt;James Newkirk (who was on the original NUnit team) made a &lt;a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html"&gt;good blog post on this&lt;/a&gt; when he moved to writing xUnit, where Setup and Teardown were removed. &lt;/p&gt;
&lt;p&gt;They make it hard to read your tests (you have to read code in two or three locations to understand what the test does) and can cause Setup/Teardown getting too many responsibilities, leading to fragility or code bloat.&lt;/p&gt;
&lt;p&gt;Either switch to setup within the individual test, or favour a Context based testing approach such as with BDD&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Tests are code, and code has to be maintained too. Make sure your tests are of a similar or higher standard than the rest of your codebase, make sure they test the right things, in the right way, and you will make your life much easier, and that of the guy who comes after you much easier too&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=51578" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Unit+Tests/default.aspx">Unit Tests</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Testing/default.aspx">Testing</category></item><item><title>The Language of Mocks (or is that Test Doubles)</title><link>http://devlicio.us/blogs/casey/archive/2008/06/11/the-language-of-mocks-or-is-that-test-doubles.aspx</link><pubDate>Wed, 11 Jun 2008 09:25:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:40953</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=40953</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=40953</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2008/06/11/the-language-of-mocks-or-is-that-test-doubles.aspx#comments</comments><description>&lt;p&gt;&lt;a class="" href="http://codebetter.com/blogs/ian_cooper/"&gt;Ian Cooper&lt;/a&gt; brought up an interesting point on the altdotnet mailing list recently, around the language used to describe Mocks, or more accurately his preference for the term Test Double over my use of the generic term Mock.&lt;/p&gt;
&lt;p&gt;In most areas of development I can often be considered a language perfectionist, for example calling something a Unit Test when it is *clearly* an Integration Test drives me nuts - but when it comes to Mocks, Stubs, Fakes, Spys, or the rather more generic Test Doubles ... I just can&amp;#39;t get passionate about the language.&lt;/p&gt;
&lt;p&gt;This all started a while ago, when people started using the term mock, but really it wasn&amp;#39;t a mock&amp;nbsp;- or more often they used the term mock when referring to what many mock frameworks call a Strict Mock, just one type of mock.&lt;/p&gt;
&lt;p&gt;Martin Fowler &lt;a class="" href="http://www.martinfowler.com/bliki/TestDouble.html"&gt;long ago posted&lt;/a&gt; on a clarification of the terminology around mocking, and xUnitPatterns has a &lt;a class="" href="http://xunitpatterns.com/Test%20Double.html"&gt;fuller description&lt;/a&gt;. The distinction that Gerard Meszaros introduced was to use the term Test Double to describe all of these things we use to help us test our code. Fakes, Spys, Mocks, Dummys ... all just a type of Test Double.&lt;/p&gt;
&lt;p&gt;Now language is important. Very important. As Ian pointed out in his email, most arguments centre around a misunderstanding of the terminology involved - I&amp;#39;m sure the world would be a nicer place if language was universal and could not be interpreted differently by different people, but then it would be a linguistically poorer place for it too.&lt;/p&gt;
&lt;p&gt;In development, language is something that is vital to good communication of what are often very complex technical concepts. We evolved the languages of patterns and principles to allow us to avoid confusion and misunderstandings, and most areas of development have their own specific language terminology.&lt;/p&gt;
&lt;p&gt;But, with this one area of testing I have a problem with the terminology, because the term that I hear from developers on a daily basis is &amp;quot;mocking&amp;quot;, not &amp;quot;test doubles&amp;quot;. And when terminology enters the common language, it is very hard to replace it with a new term just because you prefer it. I&amp;#39;m sure that Test Double describes the concept better, and I&amp;#39;m sure that it is important to have some distinction between Mocks and Fakes, but in my experience, that is not how developers refer to these things.&lt;/p&gt;
&lt;p&gt;It is much easier to say &amp;quot;we can mock this out&amp;quot; than it is to say &amp;quot;we can create a test double here&amp;quot;, the first is just more natural in the English language. So the term &amp;quot;mock&amp;quot; has become almost a defacto term for what Martin Fowler et al refer to as a Test Double, whilst also being a Mock with&amp;nbsp;a capital M for describing the Mock that most mock frameworks create.&lt;/p&gt;
&lt;p&gt;So, much as I might like to be a language perfectionist on this one, I tend to just use the term mock, and leave the decision as to whether it is a Mock, Fake, Stub or Whatever to the point I actually code it. So far nobody has misconstrued Mock to mean &amp;quot;you must use a mocking framework&amp;quot;, or at least not anyone to whom the concepts of mocking are not entirely new anyway, in which case much more clarification is needed in any case.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=40953" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category></item><item><title>Is Alt.net Duplicitous?</title><link>http://devlicio.us/blogs/casey/archive/2008/05/21/is-alt-net-duplicitous.aspx</link><pubDate>Wed, 21 May 2008 09:54:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:40674</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=40674</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=40674</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2008/05/21/is-alt-net-duplicitous.aspx#comments</comments><description>&lt;p&gt;&lt;a class="" href="http://weblogs.asp.net/rosherove/"&gt;Roy&lt;/a&gt; makes a &lt;a class="" href="http://weblogs.asp.net/rosherove/archive/2008/05/19/two-faced-commits-how-the-alt-net-community-is-becoming-more-and-more-dogmatic.aspx"&gt;number of&amp;nbsp;accusations&lt;/a&gt; about the Alt.net community, particularly centred around their espoused ideals clashing with their comments and blogs. I respect Roy greatly, his blog was one of my first real sources for great TDD information, and he has consitently put out great blog posts and software. Largely his complaints come down to TypeMock (who he now works for)&amp;nbsp;not getting an overly warm welcome by many people in the Alt.net world. &lt;/p&gt;
&lt;p&gt;I don&amp;#39;t for one second question Roy&amp;#39;s sincerity, he really has shifted his view on how testing and mocking should work, for what he sees as all the right reasons, and now he seeks to convert others to the same cause.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not what you might call a &amp;quot;paid up member&amp;quot; of the Alt.net movement, my blog address appears on altnetpedia.com, I frequent the Alt.net mailing list, but I have never attended one of the conferences, nor do I put the Alt.net logo on my site. I read a few dozen blogs, probably&amp;nbsp;a third&amp;nbsp;would be classed as Alt.net people, most would not be.&amp;nbsp;I guess I have a foot in Alt.net but dance with the devil.&lt;/p&gt;
&lt;p&gt;I am however one of the people that has commented a number of times on TypeMock and its suitability as a mocking framework (for my needs), and Roy&amp;#39;s obvious frustration comes down largely to his perception that people are bashing TypeMock unfairly, or out of dogma, and not seeing his vision for a better way to write software that TypeMock can help with.&lt;/p&gt;
&lt;p&gt;That is perhaps the case with some people. TypeMock has some fervent supporters, and there are some people that think TypeMock encourages bad practices and should be avoided - software for some reason is one of those things people become almost religious about. I suspect that most people, myself included, are somewhere in the middle.&lt;/p&gt;
&lt;p&gt;TypeMock is to me largely irrelevant. It has some plus sides (debugger support, mocking legacy and framework classes easily), and it has some down sides (it makes it &amp;quot;ok&amp;quot; to couple your code, or to use concretions over abstractions)&lt;/p&gt;
&lt;p&gt;But mostly I just cannot see the point of TypeMock as it exists. It is, if you exclude the plus and minus points I just listed for a moment, basically the same as Moq or Rhino Mocks. It does more or less the same things, in more or less the same way, except both of those options are free, and TypeMock is one of the most costly development tools you could own.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m certainly not against commercial software, I own personal licences for all the software I use on a daily basis, but those products I choose to purchase are the best in their class, or solve a particular problem I face. &lt;a class="" href="http://devlicio.us/blogs/casey/archive/2008/05/01/typemock-powerful-but-needed.aspx"&gt;I also weigh up the cost to value benefit.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The best comparison would be against unit testing frameworks, which are all to the best of my knowledge open source. There are commercial tools which make them easier to use, but there is no need for a commercial unit testing framework, as they are at least 95% feature complete. &lt;/p&gt;
&lt;p&gt;The same could be said of mocking frameworks, Rhino and Moq are at least 95% feature complete, and pretty much (in all day to day ways) the same as TypeMock. There is for me, no one &amp;quot;killer feature&amp;quot; that TypeMock has that justifies it&amp;#39;s price or putting&amp;nbsp;a dependency upon it within a code base.&lt;/p&gt;
&lt;p&gt;So is Alt.Net guilty of the duplicitous charge that Roy has made?&lt;/p&gt;
&lt;p&gt;Expecting all people who frequent the Alt.net world to be constantly flicking between technology and tool choices is not going to hold water. A typical software project may last weeks, months and possibly years. You cannot switch and change that frequently, you have to make choices and go with them. That doesn&amp;#39;t stop Alt.Net people wanting to become aware of more options, but it also means that new options have to get compared to existing options, and even when a better option comes along, it is frequently not going to be used because of historical reasons. People still have their favourites, they still have their personal biases, and they still consider themselves as capable individuals who can evaluate these things.&lt;/p&gt;
&lt;p&gt;I honestly don&amp;#39;t think TypeMock in it&amp;#39;s current form is that revolutionary that we should be sitting up and rushing to use it. The few new things it brings to the mocking party are different, not much better or that much worse. So picking the right tool for the job, means most of the time I prefer to write a wrapper or abstraction (a few wasted minutes) as opposed to changing an entire mocking strategy, all for the sake of a shinier toy. Others make take another approach. When I encounter a real world scenario where I need the power that TypeMock has, I&amp;#39;ll re-evaluate.&lt;/p&gt;
&lt;p&gt;Sometimes, the newer tool isn&amp;#39;t the right tool for the job.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=40674" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/Practices+and+Principles/default.aspx">Practices and Principles</category><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Rants/default.aspx">Rants</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Featured/default.aspx">Featured</category></item><item><title>Reflector Magic - How Hard is it to Abstract a Legacy System?</title><link>http://devlicio.us/blogs/casey/archive/2008/05/02/reflector-magic-how-hard-is-it-to-abstract-a-legacy-system.aspx</link><pubDate>Fri, 02 May 2008 11:55:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:40305</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=40305</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=40305</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2008/05/02/reflector-magic-how-hard-is-it-to-abstract-a-legacy-system.aspx#comments</comments><description>&lt;p&gt;As it sort of came up via a previous post, and on the altdotnet mailing list ... I thought I would share a little secret with you ... abstracting out legacy systems can be pretty darn simple with a bit of &lt;a class="" href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt; magic!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step One: Get Reflector&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can &lt;a class="" href="http://www.aisto.com/roeder/dotnet/"&gt;download it here&lt;/a&gt; if you don&amp;#39;t already have it (how could you be writing code without it???)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step Two: Get some Addins&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are some &lt;a class="" href="http://www.codeplex.com/reflectoraddins"&gt;really cool ones at CodePlex&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Make sure you get the &lt;a class="" href="http://code.google.com/p/doubler/"&gt;Doubler Addin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step Three: Run the Wrapper / Interface Generator&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;Pick your favourite legacy code base (MOSS is my particular favourite), pick your favourite nasty classes (SPList is just so damn sucky) ... and let Doubler work it&amp;#39;s magic.&lt;/p&gt;
&lt;p&gt;Voila!!! &amp;nbsp;... no hard to write or maintain decorators, no painful legacy system to mock, and frankly, the Doubler code is so light that you don&amp;#39;t even need to test it - just use MOSS as though it was a really well written piece of software (OK maybe that last bit is pushing the trade descriptions act a bit far).&lt;/p&gt;
&lt;p&gt;Now you can use your favourite mocking framework, no need for the magic that some provide ...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=40305" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://devlicio.us/blogs/casey/archive/tags/.NET/default.aspx">.NET</category></item><item><title>TypeMock - Powerful, but Needed?</title><link>http://devlicio.us/blogs/casey/archive/2008/05/01/typemock-powerful-but-needed.aspx</link><pubDate>Thu, 01 May 2008 14:33:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:40287</guid><dc:creator>Jak Charlton</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/rsscomments.aspx?PostID=40287</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/casey/commentapi.aspx?PostID=40287</wfw:comment><comments>http://devlicio.us/blogs/casey/archive/2008/05/01/typemock-powerful-but-needed.aspx#comments</comments><description>&lt;p&gt;A while back &lt;a href="http://weblogs.asp.net/rosherove/" target="_blank"&gt;Roy Osherove&lt;/a&gt; posted an offer to the &lt;a href="http://tech.groups.yahoo.com/group/altdotnet/" target="_blank"&gt;altdotnet mailing list&lt;/a&gt; on behalf of &lt;a href="http://www.typemock.com/" target="_blank"&gt;TypeMock&lt;/a&gt;: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Reminder: TypeMock has offered a free Typemock Isolator ent. license for one year for anyone who has registered to the current &lt;a href="http://alt.net/" target="_blank"&gt;ALT.NET&lt;/a&gt; site.&amp;amp;#xA0; Also, if you&amp;#39;re an MVP you can get the same license for free. &lt;/p&gt;    &lt;p&gt;We do ask that once you use it, you write in your site\blog at least ONE thing that you don&amp;#39;t like about it, or that could be better (it has to be constructive so that we can learn from it!) and hopefully things you like about it. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;A fine offer, how could I possibly pass it up? Hopefully this post covers that &amp;quot;ONE thing&amp;quot;.&lt;/p&gt;  &lt;p&gt;I have &lt;a href="http://blog.goinsane.co.uk/2007/11/18/UnitTestingAndMockingWithRhinoMocksAndTypeMockNET.aspx" target="_blank"&gt;looked into TypeMock before&lt;/a&gt; and found it to be &amp;quot;good&amp;quot; but not &amp;quot;good enough to make me want to switch tools&amp;quot;. My previous comparison was fairly trivial, a comparison to &lt;a href="http://www.ayende.com/projects/rhino-mocks/downloads.aspx" target="_blank"&gt;Rhino&lt;/a&gt; which I was using, but in a problem domain that included MOSS 2007, a perfect candidate for TypeMock, as it is the pure epitome of a legacy system - yes it is possible to have a legacy system upon release. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Microsoft Makes Software That Only TypeMock Can Make Mockable!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;MOSS makes life hard for developers due to a very simple, and very silly, design decision ... Microsoft like statics, they like enums, they like Internal, and they like Sealed. Far be it from me to judge their reasons behind these things, but suffice to say it makes testing a right royal pain in the posterior. &lt;/p&gt;  &lt;p&gt;TypeMock is the only mocking framework that can help with this kind of problem, as it uses the .NET profiler to intercept the parts that other frameworks cannot reach, notably it relishes mocking things like MOSS. Unfortunately, when I was working on MOSS stuff and could have used it, there was enough resistance to testing in general, that proposing we spend a not insignificant sum on a mocking framework was tantamount to bending over and asking to be kicked very hard. I couldn&amp;#39;t find any compelling reason why we should try to use TypeMock, over testing pretty close to the MOSS wire, but not right up to it. The solution I came up with was an &lt;a href="http://blog.goinsane.co.uk/2007/11/18/AbstractingSharePoint.aspx" target="_blank"&gt;abstraction of SharePoint&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;No Separation of Concerns - TypeMock to the Rescue?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now I have moved on to a new client, where my role is somewhat different. As the &amp;quot;Lead/Technical/Solutions/Whatever Architect&amp;quot; it is within my remit to recommend better ways of doing things, and in theory mocking is one of those concerns. The particular project I am overseeing is sorely lacking testing, and the concept of mocking is just not within reach. &lt;/p&gt;  &lt;p&gt;But again I find myself with no compelling reason to recommend TypeMock, and a few reasons why not to. &lt;/p&gt;  &lt;p&gt;Firstly, the thing it would have going for it ... the principle of &lt;a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank"&gt;Dependency Injection&lt;/a&gt;, or of &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_Control" target="_blank"&gt;Inversion of Control&lt;/a&gt; are, or at least have been, alien concepts to this code base. So a lot of code exists where in an ideal world we would be writing tests that would need to mock concreted dependencies, the &amp;quot;killer feature&amp;quot; of TypeMock. &lt;/p&gt;  &lt;p&gt;But this needs to be weighed against some other factors.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Is Using TypeMock Helping You Pretend Your Code Doesn&amp;#39;t Suck?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;There is a lack of testing in general, and for the few tests that do exist, they are largely integration type tests, almost all actually reading and writing data into test databases. This is the mindset that the team has got themselves into - you test against a database. They therefore see little reason to test in terms of small &amp;quot;units&amp;quot; and hence do not really see why they should mock the ADO.NET components (for example) to allow them to make those same tests without a database in place - in fact they largely see the tests as being tests of the stored procedures they have written. &lt;/p&gt;  &lt;p&gt;Then there is the concept of mocking in general. I often see this scenario, and again it is repeated, mocking is not a basic concept, before you can really get into mocking or at least can see real benefit in it, you need to have gone a long way down the unit testing road, and preferably down the test driven development road. Until you have a firm grasp on those concepts, mocking is quite a hard thing to &amp;quot;get&amp;quot; ... why would I want to mock something? Why don&amp;#39;t I just test these 5 classes together? More experienced practitioners of TDD might give a list of reasons, but testing is an art, not a science, and until you &amp;quot;get&amp;quot; unit testing for yourself ... it just doesn&amp;#39;t seem worth the effort. &lt;/p&gt;  &lt;p&gt;When you do &amp;quot;get&amp;quot; unit testing, you start to think of code in a different way, you start to think of small identifiable software components that interact together, and therefore can be tested. But unless you get DI and IoC as principles, it still seems more obvious to test the 2, 3 or 4 classes that are tightly coupled as a single unit. You need to next make that step where you see that it is more beneficial to pass dependencies into classes, rather than have them contained within the class, and often you gain this insight from an inability to write good unit tests. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;TypeMock To The Rescue!!!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;quot;You know those pesky classes that you can&amp;#39;t test because they have dependencies, well TypeMock can make those easily testable for you!&amp;quot; &lt;/p&gt;  &lt;p&gt;And, indeed this is true. It can indeed save you from all those silly DI and IoC principles - why use a &lt;a href="http://en.wikipedia.org/wiki/Strategy_pattern" target="_blank"&gt;Strategy pattern&lt;/a&gt; when there will only ever be one Strategy? &lt;/p&gt;  &lt;p&gt;Well for one thing, the tests that you found hard to write without DI/IoC were telling you something ... you had tightly coupled code, and possibly issues around the &lt;a href="http://www.objectmentor.com/resources/articles/srp.pdf" target="_blank"&gt;Single Responsibility Principle&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank"&gt;Separation of Concerns&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;At this point I can hear many screaming &amp;quot;Oh no, more damn patterns&amp;quot;, or as a developer at a previous client said to me &amp;quot;I&amp;#39;m sick of all these acronyms&amp;quot;. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Why The Pain You Felt Was Good Pain&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The foundation of good software is understanding the basic principles that developers have come to espouse over many years, and many successful and failed projects. And your hard to test classes were flashing a big red warning light over your monitor telling you that you had some potential violations. &lt;/p&gt;  &lt;p&gt;Now, with any pattern or principle, there are times when you can and should break it. But until you understand it to a fairly detailed degree, you are probably safer by choosing to follow it rather than ignore it out of ... well, ignorance. &lt;/p&gt;  &lt;p&gt;Back to TypeMock saving us earlier, and allowing us to test our classes anyway ... indeed it could have done, but for a lot of developers, it would have shielded them from potentially poor code design, and just stretched their learning process out, encouraging them to write poorer quality code, as they have a tool to get around the problem they perceive (inability to test), and not realising there is a large problem lurking (their software is rigid and will be hard to extend and evolve in future) &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;I Don&amp;#39;t Need No Damn IoC ... I Created This Dependency On Purpose&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As mentioned above, there are times when rules are made to be broken - so I am not saying TypeMock should never be used in this scenario, but unless you know the rule you are breaking, and the reason you are breaking it, and have expressed that clearly within your code base ... just don&amp;#39;t. &lt;/p&gt;  &lt;p&gt;So, on this basis a mocking framework like &lt;a href="http://www.ayende.com/projects/rhino-mocks/downloads.aspx" target="_blank"&gt;Rhino&lt;/a&gt; or &lt;a href="http://code.google.com/p/moq/" target="_blank"&gt;Moq&lt;/a&gt;, with their limitation on only being able to test code that is properly decoupled, would show you where your design was weak. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Experience on the Job Market&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Then we have the experience factor, if I recommend a tool, I want to have some confidence that developers hired on the project will have experience with it. If someone has experience with unit testing, and with mocking, the high likelihood is that their experience is around Rhino Mocks, the least likely framework they will have used is TypeMock. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How Much??? &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Then there is the real deciding factor for me recommending TypeMock, cost. &lt;/p&gt;  &lt;p&gt;Cost isn&amp;#39;t a factor on a per developer, or per project basis, the cost of 350-450 Euros certainly isn&amp;#39;t cheap, but on any serious software project it is a small drop in the ocean, at least with a good business and technical justification. &lt;/p&gt;  &lt;p&gt;Cost is a major factor as the alternatives, Rhino, Moq and others, give you 95% of the functionality, can be argued to be better as they do *not* allow mocking of tightly coupled code, and more importantly are free. &lt;/p&gt;  &lt;p&gt;On any project, when picking tools, you have to pick your fights. Do I want to expend energy getting someone to write a cheque for &lt;a href="http://www.jetbrains.com/resharper/" target="_blank"&gt;ReSharper&lt;/a&gt; for every developer, or for TypeMock? Do I want to expend energy getting agreement to use &lt;a href="http://www.castleproject.org/container/index.html" target="_blank"&gt;Windsor&lt;/a&gt; and IoC in our code base, or argue why we need to pay for TypeMock? Do I want to get agreement on &lt;a href="http://www.nunit.org/index.php" target="_blank"&gt;NUnit&lt;/a&gt; over MSTest, or spend that time arguing that investment in TypeMock will pay off? &lt;/p&gt;  &lt;p&gt;Fundamentally, a mocking framework is a very small and insignificant factor in the overall project success or failure, or even of the day to day working practices. Most other tools come as a higher priority in the decision making chain. And as such I find it hard to use (my valuable) time preparing business justifications for a tool like TypeMock, knowing full well that when asked why Rhino or Moq are not adequate for the task, that I will also be struggling for a good technical reason too. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;So Where Does That Put TypeMock?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;So, my conclusion is, that unless I have a legacy system to mock (put your favourite MS enterprise product in here), I would be very hard pressed to choose TypeMock as my mocking framework. Where I did have a legacy system to mock, I would be hard pressed to justify why we do not just buy a single TypeMock licence for our continuous integration server and treat tests against the legacy system as integration tests using TypeMock, and use another framework like Rhino for the tests that developers would be writing on a daily basis. &lt;/p&gt;  &lt;p&gt;So, how can TypeMock make itself more attractive and viable? A very good, and rhetorical, question. Dropping the cost significantly may help, but presumably they have a reasonable number of customers willing to pay that price, or they wouldn&amp;#39;t be in business, and I am thinking of a more reasonable price being in the 30-50 euro range, the level at which cost becomes insignificant as a decision point, but presumably this is just not an option. &lt;a href="http://testdriven.net/" target="_blank"&gt;TestDriven.Net&lt;/a&gt; is around 130 euros, and bang-for-buck is far ahead of TypeMock in the value game.&lt;/p&gt;  &lt;p&gt;And still ... I wouldn&amp;#39;t want inexperienced developers wielding TypeMock at their code - I would prefer they stopped, thought and figured out why they can&amp;#39;t write their test without it. When they figured it out, then they can ignore good principles from a position of strength.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=40287" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/casey/archive/tags/Practices+and+Principles/default.aspx">Practices and Principles</category><category domain="http://devlicio.us/blogs/casey/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/casey/archive/tags/Mocking/default.aspx">Mocking</category></item></channel></rss>