<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://agileisrael.org/cs/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>Search results matching tags 'Unit Testing' and 'Art Of Unit Testing'</title><link>http://agileisrael.org/cs/search/SearchResults.aspx?o=DateDescending&amp;tag=Unit+Testing,Art+Of+Unit+Testing&amp;orTags=0</link><description>Search results matching tags 'Unit Testing' and 'Art Of Unit Testing'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Comments on Corey Haines’ String Calculator TDD Kata Implementation</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/12/23/comments-on-corey-haines-string-calculator-tdd-kata-implementation.aspx</link><pubDate>Wed, 23 Dec 2009 21:26:35 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2442</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;a href="http://katas.softwarecraftsmanship.org/?p=80"&gt;Corey Haines recreated&lt;/a&gt; my &lt;a href="http://osherove.com/tdd-kata-1/"&gt;TDD Kata&lt;/a&gt; on his KataCasts blog.&amp;#160; (&lt;a href="http://5whys.com/blog/how-to-measure-programmer-productivity-using-tdd-katas.html"&gt;click here to learn more about TDD katas&lt;/a&gt;)&lt;/p&gt;  &lt;p&gt;Since Corey is an experienced TDD practitioner I was honored that he’d given it a go, and was eager to see the video. Later, corey asks for my remarks on it, which i will gladly put here. In general, Corey’s video is a great piece of TDD work to watch as an example of a master TDDer doing his thing. Everything flows gracefully and the code produced is simple, readable and of course – &lt;strong&gt;works&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;I especially loved the large amount of merciless refactoring Corey made during the Kata. As you TDD you should not cut any corners in the refactoring area – and almost after every passing test or two, Corey does refactoring to some very simple code patterns. &lt;/p&gt;  &lt;p&gt;Another worthy note – Corey takes care in refactoring the tests as well throughout the kata. Kudos!&lt;/p&gt;  &lt;p&gt;A few things that stood out for me can be thought of as very little things – and are mostly questions:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Partial Test:&lt;/strong&gt; at some point, Corey seems to be writing the tests incrementally as well, in that he writes an empty test that passes, and then fills in the test itself to see it fail (which is usually where I start). I wasn’t sure why he’d do that, but the reasoning could be that he wants to make sure the environment works for the test. since he does it all in Ruby, which is a more forgiving environment for typing errors, this might be it.       &lt;p&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Always passing test&lt;/strong&gt;: very early on, in the second test actually, Corey creates a test that asserts that sending “0” returns “0” – which &lt;em&gt;passes&lt;/em&gt; and &lt;em&gt;never fails&lt;/em&gt;. That is because by default empty strings as input return zero. I do it a bit differently – i try to start with a failing test that drives more functionality, and if i can find a way to make a test for “0” fail as well to being, i will do it (so that i can ‘test the test’ in TDD style).       &lt;p&gt;&lt;u&gt;&lt;em&gt;A different way&lt;/em&gt;&lt;/u&gt;: Don’t write a passing test for “0” input. instead write a &lt;em&gt;failing test &lt;/em&gt;for “1” input. Another options would have been to indeed start with a &lt;em&gt;passing test for “0” input&lt;/em&gt;, but then to go production code and deliberately return –1 to see the test fail, then fix it to return “0”, see the test pass again, and move on to the next test. &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Magic inputs&lt;/strong&gt;: Corey sends in various seemingly random, out of the air numbers as inputs to the tests starting from the third test onwards. For example, to a reader who sees a test that says “sending in 5 returns 5” that reader might ask themselves “why 5? why is 5 so special? should I also use 5 in my tests?”.       &lt;p&gt;&lt;em&gt;&lt;u&gt;A different way&lt;/u&gt;&lt;/em&gt;: To avoid such confusion i like to stick to the lowest common version of an input that still proves the application wrong. if sending in “1” produces the same result as sending in “5” then my all means i will send in “1”. If the input is 2 digits, I’d send in “10”, “100” and so on. If the input still does not make sense I would put it in as a variable named “SINGLE DIGIT NUMBER” to explain to the reader what is so special or not so special about this value.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;strong&gt;The simplest Test:&lt;/strong&gt;Corey wrote the tests for inputs with \newline characters without considering the most basic test for this kind: a simple string containing only a new line character (equivalent to an empty string). I agree that not everyone would pick up on this as an idea, since you might feel this is an invalid input into the system. nevertheless, &lt;a href="http://osherove.com/training/"&gt;when I teach TDD&lt;/a&gt; this is the way i teach the kata. It feels lime a more natural incremental evolution of the code and tests, and a good way to send the message that &lt;em&gt;anything can be divided into small increments if you want to&lt;/em&gt;.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;strong&gt;Refactor to un-readability&lt;/strong&gt;: At some point Corey refactors the code that handles delimiter characters into a single line of Ruby code. while it &lt;em&gt;is&lt;/em&gt;a form of refactoring, i found that the code after refactoring was much less readable than it was before. &lt;/p&gt;      &lt;p&gt;&lt;em&gt;&lt;u&gt;A different way&lt;/u&gt;&lt;/em&gt;: I try to avoid any “immediate if”s or single line “smart” statements that feel more “smart” than “simple”. When i have to choose between length and readability, i will choose length every time. this makes sure the reader is always comfortable with the code.&lt;/p&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Summary:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;These small things aside, I think Corey’s video is a great example of TDD in practice! &lt;a href="http://katas.softwarecraftsmanship.org/?p=80"&gt;Go watch it&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7289541" width="1" height="1" alt="" /&gt;</description></item><item><title>Test driven design – Willed vs. Forced Designs</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/11/12/test-driven-design-willed-vs-forced-designs.aspx</link><pubDate>Thu, 12 Nov 2009 21:59:48 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2401</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;I’m writing this as a typemock employee, but also as someone who has sat on the other side of the line for several good years, and can argue in both ways. The following, I feel, is true no matter where I work.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;There are two ways people use tests to drive design, as far as I see. one is great, and I agree with, the other is not so great and I don’t agree with it. Sadly, both of them are categorized together these days, and the baby gets thrown out with the bath water - You either use both (BAD) or you use neither (BAD!)&lt;/p&gt;  &lt;p&gt;Here are the two usage patterns:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;#1 Willed Design&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;By writing tests, you can observe the usability of your design from a consumer perspective, and can decide whether or not you like it, and change it accordingly&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;#2 Forced Design&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;By using a subset of the available isolation frameworks(rhino, moq, nmock) or specific techniques *manual mocks and stubs) you discover cases that are not technically “mockable” or “fakeable” and use that as a sign for design change.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I highly agree with #1, and highly disagree with #2.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;#1 makes sense.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You get to decide what is a good and bad design, and the experience of using that design from the test perspective is your guideline. But &lt;strong&gt;you&lt;/strong&gt; make the rules on what you like and don’t like.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;#2 is problematic for several reasons:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The tool decides. Not you.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You let an automated tool (rhino mocks, Moq etc..) tell you when your design is OK or not. That point alone should go against anything ALT.NET has ever stood for, doesn’t it? If you need a tool to tell you what is good or bad design, then you &lt;strong&gt;are doing it wrong&lt;/strong&gt;. You should either know good design beforehad, or you shoud pair program together to find the best design, or you should learn by a mentor who can review your design mistakes, but don’t ever let a tool tell you what is right and what isn’t, especially when the only reason that tool works for that is by chance and not on purpose&amp;#160; (as you’ll see in the next point)&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A technical limitation that grew into something else&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;tools like rhino and MOQ and NMOCK &lt;strong&gt;just happen&lt;/strong&gt; to support some OO ideas that seem good enough for design activities because of the underlying technology they use underneath. It’s pretty simple – they all use some form of either generating code at runtime that inherits from a class or interface, and then overrides methods on it (therefore they need to be virtual methods and non sealed classes, or an interface) or they use a proxy of some kind which underneath does pretty much the same things. (typemock is an exception since it uses a profiler api which has non of these requirements) . &lt;strong&gt;simply that means&lt;/strong&gt; that the reason rhino, or MOQ or NMOCK “let you know” that you should use an interface somewhere, is a technical limitation of the tools, not a choice. Ayende was asked once what he’d do if he was technically able to fake static methods in rhino mocks – would he add that feature? “in the blink of an eye” he answered. and I agree. adding more options to the tool just extends the limitations of the possible design under test, not the “goodness” of it.&lt;/p&gt;  &lt;p&gt;Languages like Ruby, Javascript, Python etc.. have isolation frameworks (or in some cases don’t even need such frameworks) that fully support any type of behavior changing, regardless of the design, since the language is less strict. yet, somehow, proper design arises in those languages tool. perhaps those languages are just “too powerful” and should not be used because they will cause you to do bad design? see the previous point for my answer.&lt;/p&gt;  &lt;p&gt;What happens if tomorrow, or using C# 4.0 those tools get such abilities? will you all stop using them?&lt;/p&gt;  &lt;p&gt;of course, you don’t have to use isolation frameworks to be dissuaded by the idea of limiting your design by using something – in this case a technique: using manual mocks and stubs in an object oriented language is just as “limiting” technically as is using one of those frameworks. You’re still bound to play within the simple laws of OO and using a design that is even a little out of place (even though it might make perfect sense for your application for security, performance or other reasons) is either untestable, or a general no no. &lt;/p&gt;  &lt;p&gt;see the previous point for what i think about that. &lt;/p&gt;  &lt;p&gt;the point here is that you’re using a technical limitation of a tool or a technique to tell you what to do instead of thinking for yourself and learning proper design guidelines. that limitation &lt;strong&gt;just happens&lt;/strong&gt; to be somewhat partially consistent with what you might currently to believe to be true for design. but technically, it is a limitation that could end soon. when it changes it’s behavior, will you just change your design guidelines? switch or won’t upgrade to a new version of the language? or actually start using your head and your peers to see what’s right and what’s not?&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Typemock Dilemma&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Typemock gets a lot of flack for not inhibiting the design of the program, and I can see how people would be afraid to lose that limitation in other tools, since all they head from alpha geeks in .NET is that if it’s not “testable” then your design is wrong. worse, they hear “if you need typemock your design is wrong”. &lt;/p&gt;  &lt;p&gt;there’s nothing a silly as absolute “fact” theories in the software world. In fact, let me go out and say that &lt;strong&gt;all fact theories are wrong&lt;/strong&gt;. How that’s for irony?&lt;/p&gt;  &lt;p&gt;The message should be, I feel, more like “here are some principles of good design as we think of it today”, but instead it is based on tool choice and not on technicques or craftsmanship.&lt;/p&gt;  &lt;p&gt;Unfortunately, I don’t think getting rid of #2 is possible in .NET today without using a tool like typemock, and that’s a shame, since it means that, because it costs money, people in the community will still want to use the free tools, which force design, instead of allowing them to decide on it like the mature developers they are.&lt;/p&gt;  &lt;p&gt;Maybe it’s time to have some sort of free version of Isolator so that everyone can benefit. what do you think?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7252833" width="1" height="1" alt="" /&gt;</description></item><item><title>Minimizing unit Test Fragility – 8 features in Typemock Isolator to help</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/07/09/minimizing-unit-test-fragility-8-features-in-typemock-isolator-to-help.aspx</link><pubDate>Thu, 09 Jul 2009 22:52:50 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2288</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;in continuation &lt;a href="http://weblogs.asp.net/rosherove/archive/2009/07/09/preventing-fragile-tests-how-can-isolation-frameworks-help-or-hinder-your-goal.aspx"&gt;to my challenge&lt;/a&gt; (which no one had bothered answering, lazy web!)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_764311FD.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;margin:0px 15px 0px 0px;display:inline;border-top:0px;border-right:0px;" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_3B3B939A.png" width="240" height="205" /&gt;&lt;/a&gt; One of the things that inhibits unit tests in organizations is the idea of &lt;em&gt;fragile&lt;/em&gt; tests. a Fragile test is a test that can easily break when the production code changes. That’s not to say that tests should &lt;em&gt;never&lt;/em&gt; break as you change production code, but there are ways to minimize this effect so that when tests &lt;em&gt;do &lt;/em&gt;break, they break for the &lt;em&gt;right&lt;/em&gt;&amp;#160; reason.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;the right reason&lt;/strong&gt; is when a feature in production code isn’t working.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;the wrong reasons&lt;/strong&gt; can be many and varied. Of the most common ones is the idea of over specification in tests. The more your test expects of your code’s internal implementation, the more “specified” it is, the more “expectations” it has on the internals of the code. since internal code is more prone to change, so will the test break more often. so the situation can occur that the production code changed, but still gets the job done, but since it’s doing it differently internally, the test breaks even though the end result is still OK.&lt;/p&gt;  &lt;p&gt;One of the main ideas in the new Isolator API was to reduce the fragility of tests by default. there are several features in Typemock Isolator that remove lots of fragility from tests by default, compared to other tools:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;All Fakes are non strict by default&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Recursive Fakes&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Method stubs ignore parameters by default &lt;/li&gt;    &lt;li&gt;“From now on” Method behavior as a default &lt;/li&gt;    &lt;li&gt;Isolate.Swap.AllInstances &lt;/li&gt;    &lt;li&gt;Isolated.NonPublic APIs will not break when refactoring from private to public &lt;/li&gt;    &lt;li&gt;Ignore one or all static methods on a type &lt;/li&gt;    &lt;li&gt;True Properties &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;li&gt;&lt;u&gt;&lt;strong&gt;All Fakes are non strict by default&lt;/strong&gt;. &lt;/u&gt;    &lt;p&gt;when a fake object is strict, then it will throw an exception when someone calls one of its methods that wasn’t specifically “expected” by the test (or a different number of times than expected). since internal code can change and start interacting with other code in different ways, strict fakes will almost always fail your test on the lightest nuance of change. Most frameworks used to have strict fakes by default.&lt;/p&gt;    &lt;p&gt;Isolator has all fakes non strict by default. in fact, there is no “strict” mode at all.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;(); &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//code under test can now call any method without the test needing to specify it. the test only needs to specify behavior of methods it cares about.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;u&gt;&lt;strong&gt;Recursive Fakes&lt;/strong&gt;&lt;/u&gt;     &lt;p&gt;This is a feature first introduced by Isolator more than a couple of years ago and then adopted by Moq and Rhino Mocks. the idea is simple : allow chained calls in your code without the test needing to specify fakes at each hierarchy level. for example, calling MyFake.SomeProperty.DoSomething() will, by default, do nothing since its root is a fake object. the “SomeProperty” will be initialized by default to a fake object as well, recursively down the line.&lt;/p&gt;    &lt;p&gt;With other frameworks this will only work with interfaces, methods which are virtual and classes that are non sealed. Isolator can make this work with anything, including static methods and non sealed classes.&lt;/p&gt;    &lt;p&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;(); &lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//code under test can &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;fake.SomeProperty.DoSomething()&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//or&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var propObj = fake.SomeProperty;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;propObj.DoSomething();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;As your internal code is refactored, or changed to call a method down the hierarchy, this should not break a test (as long as the method does not matter to the test)&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Method stubs ignore parameters by default &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;all other frameworks except Isolator will use the values being sent to methods of fake objects during the “setup” phase, as expectations of these actual values. Isolator by default ignores values being sent in, and just returns the fake result we tell it to, no matter what was being sent in. Of course, you *could* tell it to use the exact argument values, but that is not the default behavior.&lt;/p&gt;    &lt;p&gt;other frameworks will require that you put in special constraints on each parameter value to say that you don’t care about the actual value.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var o = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;const int IGNORED_VALUE=10;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;object IGNORED_OBJECT= null;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.WhenCalled(()=&amp;gt; o.SomeMethodWithParams(“ignored string”,IGNORED_VALUE,IGNORED_OBJECT) ).WillReturn(3);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;this method will return 3 no matter what parameters are being sent to it. so internal code can change parameters slightly and it will still work.&lt;/p&gt;    &lt;p&gt;by specifying only on specify param values, we could be over specifying the test.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;“From now on” Method behavior as a default &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;with Isolator, once you set behavior on a method (“Ignore”, WillReturn(..), WillThrowException(..) ), it will use that as its default behavior for all subsequent calls. That way, if the internal code ends up calling a method more than once, the test should not care about it (as long as the result does not hurt the test). This is great for ignore calls to “Log” objects and such, where you don’t know or care how many times it will be called. you just want to ignore them without having to worry if the code will use them or not.&lt;/p&gt;    &lt;p&gt;for example, the method from the code above will *always* return 3, no matter how many times it will be called.&lt;/p&gt;    &lt;p&gt;if we specified it twice with different return values, it will return the *last* behavior as the default, after it was called once with the previous behavior.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Isolate.Swap.AllInstances &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;This beauty will replace all existing and future instances of a specific type in the code under test with the fake type. that way you don’t care how many times some object might be created, or how many instances of it are used. for “util” type objects, this makes things a breeze to setup for a test that could be very complicated or impossible in other frameworks.&lt;/p&gt;    &lt;p&gt;as the internal code changes with usage of these types, the test will still pass.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.WhenCalled( ()=&amp;gt; fake.Foo() ).IgnoreCall();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.Swap.AllInstances&amp;lt;SomeType&amp;gt;().With(fake);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//now production code can do this:&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var x = new SomeType();//&amp;lt;—this will behave like the fake object we created&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Isolated.NonPublic APIs will not break when refactoring from private to public &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;Isolator allows setting method behavior on non public methods as well:&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var x = new SomeObject();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.NonPublic.WhenCalled(x,”SomeMethod”).WillReturn(3);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;The beauty is that if you do refactor the method to make it public, the test won’t nudge you or throw an exception. It will just work with public methods as well. You can then refactor the test without being a slave to it.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Ignore one or all static methods on a type &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.Fake.StaticMethods&amp;lt;SomeType&amp;gt;()&lt;/font&gt; will ignore all void methods on that type, and return recursive fakes on all functions. That way, if you add more methods to that type, the test won’t care about it.&amp;#160; great for utility style classes with lots of static methods.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;True Properties &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;“True properties” is a feature that Isolator picked up from Rhino Mocks – you can set properties on a fake object as if they were real properties.&lt;/p&gt;    &lt;p&gt;The nice thing is that if internal code then sets these properties to values you don’t care about, the test will work just fine. it’s also very readable.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;fake.SomeProperty=3; //will behave like a real property and return 3;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/li&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7144028" width="1" height="1" alt="" /&gt;</description></item><item><title>Art of Unit Testing on Hanselminutes</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/07/07/art-of-unit-testing-on-hanselminutes.aspx</link><pubDate>Tue, 07 Jul 2009 12:28:40 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2285</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_5D7B81D7.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;margin:0px 10px 0px 0px;display:inline;border-top:0px;border-right:0px;" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_27F98A51.png" width="193" height="244" /&gt;&lt;/a&gt; &lt;a href="http://www.hanselman.com/blog/"&gt;Scott Hanselman&lt;/a&gt; took me in for a 30 minute interview about Unit Testing Dos and Don’ts in his podcast, Hanselminutes. It was a pleasure, and I hope to be there once more about other topics. Maybe in TechEd Berlin..&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.hanselminutes.com/default.aspx?showID=187"&gt;Have a listen&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7142874" width="1" height="1" alt="" /&gt;</description></item><item><title>Testing that an event was raised</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/05/23/testing-that-an-event-was-raised.aspx</link><pubDate>Sat, 23 May 2009 18:25:20 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2264</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;This question keeps coming up: “How can I test that an event was actually raised from my class under test?”&lt;/p&gt;  &lt;p&gt;actually, there is an easy way to check if an event was raised.    &lt;br /&gt;you subscribe to the event in your test, and in the event handler you set a boolean flag to true. then you just assert on the flag.     &lt;br /&gt;here is a quick example: &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000"&gt;public void Test()      &lt;br /&gt;{       &lt;br /&gt;bool wasRaised=false;       &lt;br /&gt;var button = new Button;       &lt;br /&gt;button.Click += ()=&amp;gt; wasRaised=true;       &lt;br /&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent();       &lt;br /&gt;Assert.IsTrue(wasRaised);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;If you feel less comfortable using lambdas:&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="c"&gt;public void Test()      &lt;br /&gt;{       &lt;br /&gt;bool wasRaised=false;       &lt;br /&gt;var button = new Button;       &lt;br /&gt;button.Click += delegate&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#800000" face="c"&gt;{ &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000" face="c"&gt;wasRaised=true&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000" face="c"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font color="#800000" face="c"&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent();      &lt;br /&gt;Assert.IsTrue(wasRaised);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Unfortunately, with VB.NET’s current version, doing this in a single method is next to impossible, so you are forced to register to the event with a method at the class level, and check that:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Code (VB.NET):&lt;/b&gt; &lt;/p&gt; &lt;font color="#800000" face="Consolas"&gt;dim wasRaised as Boolean=false;    &lt;br /&gt;&lt;/font&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;public sub test()        &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;wasRaised=false     &lt;br /&gt;dim button = new Button()      &lt;br /&gt;AddHandler( button.Click , AddressOf(OnClick))&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent()     &lt;br /&gt;Assert.IsTrue(wasRaised);      &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;end sub&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;public sub OnClick(source as object,e as EventArgs)&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;wasRaised=true&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;end sub&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7095427" width="1" height="1" alt="" /&gt;</description></item><item><title>Art Of Unit Testing (The Samurai Book)– Get it now, it’s done.</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/05/20/art-of-unit-testing-the-samurai-book-get-it-now-it-s-done.aspx</link><pubDate>Wed, 20 May 2009 21:22:14 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2262</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;The time has actually come. After 2.5 years, and two kids, &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;my book is finally done&lt;/a&gt; and is available in full form as an EBook. at the end of the month it will be in print form. Now would be the time to get it, when it is still at a “pre-order” pricing. Get the preorder price either &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;at Manning&lt;/a&gt;(along with the EBook) or at &lt;a href="http://www.amazon.com/exec/obidos/ASIN/1933988274/iserializable-20" target="_blank"&gt;the amazon page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I love the cover image. How about we call this “The Samurai book” from now on?&lt;/p&gt;  &lt;p&gt;This is the book that I wished I had when I started out writing my first tests, and that combines my knowledge about unit testing from the past 5-6 years or so working with companies on real projects (and real failures).&lt;/p&gt;  &lt;p&gt;It contains things I have not seen in other places – writing readable, maintainable and trustworthy tests, as well as guidelines on how to review someone else’s tests and what to watch out for.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;margin-left:0px;border-left-width:0px;margin-right:0px;" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_6E3CE98B.png" width="273" height="347" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I was lucky to have the foreword written by no other than &lt;a href="http://www.amazon.com/exec/obidos/ASIN/0131177052/iserializable-20" target="_blank"&gt;Michael-Legacy-Code-Feathers&lt;/a&gt; himself, and with some great quotes including one from Kent Beck about the book.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here is the &lt;a href="http://www.manning.com/osherove/excerpt_contents.html" target="_blank"&gt;Table of Contents&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Free Chapters&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The book comes with two free chapters:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Chapter 1 &lt;/strong&gt;– &lt;a href="http://www.manning.com/osherove/SampleChapter1.pdf" target="_blank"&gt;The basics of unit testing(PDF)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Chapter 3 &lt;/strong&gt;– &lt;a href="http://www.manning.com/osherove/SampleChapter3.pdf" target="_blank"&gt;Using Stubs to Break Dependencies (PDF)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Or &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;get the full book&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Book description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Unit testing, done right, can mean the difference between a failed project and a successful one, between a maintainable code base and a code base that no one dares touch, and between getting home at 2 AM or getting home in time for dinner, even before a release deadline.&lt;/p&gt;  &lt;p&gt;&lt;i&gt;The Art of Unit Testing&lt;/i&gt; builds on top of what&amp;#39;s already been written about this important topic. It guides you step by step from simple tests to tests that are maintainable, readable, and trustworthy. It covers advanced subjects like mocks, stubs, and frameworks such as Typemock Isolator and Rhino Mocks. And you&amp;#39;ll learn about advanced test patterns and organization, working with legacy code and even untestable code. The book discusses tools you need when testing databases and other technologies. It&amp;#39;s written for .NET developers but others will also benefit from this book.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What’s inside:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Test Review Guidelines &lt;/li&gt;    &lt;li&gt;How to create readable, maintainable, trustworthy tests &lt;/li&gt;    &lt;li&gt;Stubs, mock objects, and automated frameworks &lt;/li&gt;    &lt;li&gt;Working with .NET tools, including NUnit, Rhino Mocks and Typemock Isolator &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7093756" width="1" height="1" alt="" /&gt;</description></item><item><title>Test Review #3 – Unity</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/03/23/test-review-3-unity.aspx</link><pubDate>Mon, 23 Mar 2009 05:58:55 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2228</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Watch previous videos:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx"&gt;Test Review #1 – NerdDinner&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/21/test-review-2-asp-net-mvc-unit-tests.aspx"&gt;Test Review #2 – ASP.NET MVC&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;object width="437" height="370" id="viddler_RoyOsherove_6"&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;param name="movie" value="http://www.viddler.com/player/43373a0e/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;embed src="http://www.viddler.com/player/43373a0e/" wmode="transparent" width="437" height="370" type="application/x-shockwave-flash" /&gt;&lt;/embed&gt;&lt;/object&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In this video I go over the tests for Microsoft Unity Application Block.&lt;/p&gt;  &lt;p&gt;Overall the quality of the tests in Unity is pretty good! I could certainly recommend that people look at them as examples of a bunch of tests against a framework, which are mostly very readable and maintainable. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Things I walk through:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Using [Ignore] &lt;/li&gt;    &lt;li&gt;exploration testing &lt;/li&gt;    &lt;li&gt;magic numbers and strings &lt;/li&gt;    &lt;li&gt;un-needed asserts &lt;/li&gt;    &lt;li&gt;Stub hard coded behavior &lt;/li&gt;    &lt;li&gt;handling config files in tests &lt;/li&gt;    &lt;li&gt;Asserts hidden in a utility method &lt;/li&gt;    &lt;li&gt;more naming conventions &lt;/li&gt;    &lt;li&gt;Separating integration tests &lt;/li&gt;    &lt;li&gt;“smart” code that is less readable &lt;/li&gt;    &lt;li&gt;Meaningless “isNotNull” tests &lt;/li&gt;    &lt;li&gt;cleaner ways of expecting exceptions &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6994263" width="1" height="1" alt="" /&gt;</description></item><item><title>Test Review #2 – ASP.NET MVC Unit Tests</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/03/21/test-review-2-asp-net-mvc-unit-tests.aspx</link><pubDate>Sun, 22 Mar 2009 03:42:38 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2227</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;See other reviews: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx"&gt;Review #1: NerdDinner&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s the second video review of Unit Tests. This is another one written by Microsoft – &lt;a href="http://www.codeplex.com/aspnet"&gt;ASP.NET MVC&lt;/a&gt; (&lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471"&gt;source&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;First, it’s important to state how surprised I was by the &lt;strong&gt;high quality&lt;/strong&gt; of the tests in MVC. The tests are &lt;strong&gt;readable, maintainable and trustworthy, &lt;/strong&gt;with very little issues that I could find. whatever Issues I found are rather easy to fix. In any case, if one is looking for examples of systems written in what seems almost entirely in TDD, or at the minimum with very good testing guidance, ASP.NET MVC should be a good stop to look at.&lt;/p&gt;  &lt;p&gt;&lt;object width="437" height="370" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/a30fe2d4/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed src="http://www.viddler.com/player/a30fe2d4/" width="437" height="370" type="application/x-shockwave-flash" wmode="transparent"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;  &lt;p&gt;Issues discussed in this video:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Implementing RowTest with MSTest, and the importance of naming (14:00)&lt;/li&gt;    &lt;li&gt;Verify() that is splitted from the mock expectations (17:00)&lt;/li&gt;    &lt;li&gt;some naming conventions&lt;/li&gt;    &lt;li&gt;Over-specification in tests (mainly more than one mock object per test)&lt;/li&gt;    &lt;li&gt;verifying mocks when it’s not required&lt;/li&gt;    &lt;li&gt;logic inside tests (concatenation)&lt;/li&gt;    &lt;li&gt;test factory methods with too much logic&lt;/li&gt;    &lt;li&gt;a very good example of when &lt;strong&gt;multiple asserts&lt;/strong&gt; is really bad (11:50)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Again – I’m very pleased with the test quality. Now is the time to make sure the things above are fixed. they are still important!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6988868" width="1" height="1" alt="" /&gt;</description></item><item><title>Test Review #1 - NerdDinner</title><link>http://agileisrael.org/cs/blogs/royo/archive/2009/03/20/test-review-1-nerddinner.aspx</link><pubDate>Fri, 20 Mar 2009 11:45:53 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2225</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;I’ve decided to start doing some test reviews of tests that I see in the wild. I figured it’s the best way to show people what I mean when I say they do not have readable, maintainable or trustworthy tests.&lt;/p&gt;  &lt;p&gt;The first episode is the review of the tests from the &lt;a href="http://nerddinner.codeplex.com/"&gt;NerdDinner MVC source code&lt;/a&gt;. It’s 30 minutes long. and it was shot at 2AM, so I’m quite cranky. But the tests sure don’t try to ease my mind, and only make me crankier. &lt;/p&gt;  &lt;p&gt;If you have tests you’d like me to review send an email to Roy AT osherove.com with the subject “Test Review [project name]”&lt;/p&gt;  &lt;p&gt;&lt;object width="437" height="370" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/6180e63a/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed src="http://www.viddler.com/player/6180e63a/" width="437" height="370" type="application/x-shockwave-flash" wmode="transparent"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;problems that are dealt with in this video:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Naming conventions&lt;/li&gt;    &lt;li&gt;Magic strings in tests&lt;/li&gt;    &lt;li&gt;Hard coded values in hand written stubs&lt;/li&gt;    &lt;li&gt;Magic assertions (expecting a value that no one understand why it should be that value)&lt;/li&gt;    &lt;li&gt;Lack of tests&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6981302" width="1" height="1" alt="" /&gt;</description></item><item><title>Isolator Feature Focus: Duck Typing and Isolate.Swap</title><link>http://agileisrael.org/cs/blogs/royo/archive/2008/11/02/isolator-feature-focus-duck-typing-and-isolate-swap.aspx</link><pubDate>Sun, 02 Nov 2008 12:25:00 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:2131</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;a href="http://www.typemock.com/commdl.php"&gt;Typemock Isolator 5.1.1&lt;/a&gt; has been released, and this release brings with it some awesome (seriously) features that are unique fro any other framework I&amp;#39;ve seen.&lt;/p&gt;  &lt;p&gt;a &lt;a href="http://blog.typemock.com/2008/10/typemock-isolator-511-is-out.html"&gt;good overview of features can be found here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Isolator Swap feature &lt;/strong&gt;allows swapping calls between real and fake objects (kind like redirects) so that any relevant calls made against the real object will be redirected and invoked on the fake object. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Here&amp;#39;s how you use it:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/IsolatorFeatureFocusDuckTypingandIs.Swap_CC8A/image_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="133" alt="image" src="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/IsolatorFeatureFocusDuckTypingandIs.Swap_CC8A/image_thumb.png" width="340" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Unlike doing a standard &amp;quot;WhenCalled()&amp;quot; on some object method and telling what its custom behavior will be, &amp;quot;Swapping&amp;quot;&amp;#160; objects redirects &lt;strong&gt;all &lt;/strong&gt;relevant calls(I&amp;#39;ll explain what &amp;quot;relevant&amp;quot; means in a second) to the fake object which you have created.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;strong&gt;Duck Typing Awesomeness&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Another cool thing about it is that &amp;quot;Duck&amp;quot; and &amp;quot;Dog&amp;quot; don&amp;#39;t have to have a shared interface or base class. The &amp;quot;Swap&amp;quot; feature will redirect a method call if it exists on the &amp;quot;fake&amp;quot; object, but if it does not, it will invoke the original object. This is one interpretation of what&amp;#39;s called &amp;quot;&lt;a href="http://haacked.com/archive/2007/08/19/why-duck-typing-matters-to-c-developers.aspx"&gt;Duck Typing&lt;/a&gt;&amp;quot;.&lt;/p&gt;  &lt;p&gt;The &amp;quot;CallsOn&amp;quot; and &amp;quot;WithCallsTo&amp;quot; methods take an object type, so you can send in anything you want.&amp;#160; if a method on the fake object matches the signature and name of a called method on the real object, the fake method will be invoked.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716046" width="1" height="1" alt="" /&gt;</description></item></channel></rss>