<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Develop Using .net</title>
    <link>http://developusing.net/</link>
    <description />
    <language>en-us</language>
    <copyright>Dennis Burton</copyright>
    <lastBuildDate>Wed, 20 May 2009 14:38:30 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>dennis@developusing.net</managingEditor>
    <webMaster>dennis@developusing.net</webMaster>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/DevelopUsingdotnet" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=8c7fd586-6e53-411a-9956-91b19585601e</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,8c7fd586-6e53-411a-9956-91b19585601e.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,8c7fd586-6e53-411a-9956-91b19585601e.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8c7fd586-6e53-411a-9956-91b19585601e</wfw:commentRss>
      
      <title>Conference Season is Here!</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,8c7fd586-6e53-411a-9956-91b19585601e.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/Q8NbdUYoarE/ConferenceSeasonIsHere.aspx</link>
      <pubDate>Wed, 20 May 2009 14:38:30 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;Speaking at CodeStock 2009&lt;/b&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This year &lt;a href="http://www.codestock.org/"&gt;CodeStock&lt;/a&gt; is shaping up to be a&#xD;
conference like no other. Most regional conferences have around 25 sessions with some&#xD;
attempt to do Open Spaces on the side. &lt;a href="http://www.codestock.org/"&gt;CodeStock&#xD;
2009&lt;/a&gt; will certainly blow the doors off the norm with a community driven event&#xD;
with something to offer for everyone. To start with, it is the first conference that&#xD;
I know of that allowed the early registering attendees to choose the direction for&#xD;
the more than 50 hour-long &lt;a href="http://www.codestock.org/Sessions.aspx"&gt;sessions&lt;/a&gt; as&#xD;
well as 6 extended hands-on &lt;a href="http://www.codestock.org/Sessions.aspx"&gt;sessions&lt;/a&gt;.&#xD;
Then, to kick it up one more notch, &lt;a href="http://netcave.org/"&gt;Alan Stevens&lt;/a&gt; will&#xD;
be facilitating the Open Spaces. Make no mistake: Alan knows how to do Open Spaces&#xD;
right. Last year’s CodeStock was the moment the community took notice of the way that&#xD;
Alan’s particular talent set meshes with coordinating an exceptionally effective Open&#xD;
Space event. This is truly an event that has something to offer everyone.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Given the community selection process, it is even more of an honor to be selected&#xD;
to speak at this event. I will be giving the PatternsInTesting presentation that has&#xD;
already been well received in the Midwest area.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;Indy Code Camp 2009&lt;/b&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I was privileged to be able to give the PatternsInTesting presentation at Indy Code&#xD;
Camp this year. There were many really good testing related conversations before and&#xD;
after the presentation. I am encouraged by the amount of interest the community is&#xD;
taking towards improving the adoption of test driven design. I also got to see a few&#xD;
top notch presentations:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://blog.timwingfield.com/"&gt;Tim Wingfield&lt;/a&gt; - Care About Your Craft:&#xD;
A very motivating presentation on doing the right thing &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://www.japikse.blogspot.com/"&gt;Philip Japikse&lt;/a&gt; - CRUD Sucks! NHibernate&#xD;
to the rescue: Phil has an impressive in depth knowledge of NHibernate. I was most&#xD;
fascinated by all of the extensions that he has written to really make NHibernate&#xD;
hum. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://jonfuller.codingtomusic.com/"&gt;Jon Fuller&lt;/a&gt; - Dealing with Dependencies:&#xD;
This was my favorite presentation of the day. Jon had only enough slides for an overview&#xD;
and went directly in to writing code. It was an in depth, working look at using DI&#xD;
tools. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://mjeaton.net/blog/"&gt;Michael Eaton&lt;/a&gt; - Developing Solid WPF Applications:&#xD;
A very informative view into a real world WPF application and its development evolution &#xD;
&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;Greater Lansing .net User Group&lt;/b&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
A big thank you to &lt;a href="http://glugnet.org"&gt;GLUGnet&lt;/a&gt; for letting me do the&#xD;
PatternsInTesting presentation for the group. This is a group that I frequently attend,&#xD;
it is nice to be able to present on a topic that I talk about so much with the members&#xD;
of that group.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=8c7fd586-6e53-411a-9956-91b19585601e"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=Q8NbdUYoarE:Ufr_uH7m48M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/Q8NbdUYoarE" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,8c7fd586-6e53-411a-9956-91b19585601e.aspx</comments>
    <feedburner:origLink>http://developusing.net/2009/05/20/ConferenceSeasonIsHere.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=6a0a4830-21e5-4012-a67a-51adcc156475</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,6a0a4830-21e5-4012-a67a-51adcc156475.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,6a0a4830-21e5-4012-a67a-51adcc156475.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6a0a4830-21e5-4012-a67a-51adcc156475</wfw:commentRss>
      <slash:comments>1</slash:comments>
      
      <title>PatternsInTesting[3] - Spy Pattern</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,6a0a4830-21e5-4012-a67a-51adcc156475.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/1o6KCXdTMnI/PatternsInTesting3SpyPattern.aspx</link>
      <pubDate>Tue, 19 May 2009 14:49:32 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
Your mission, should you choose to accept it, is to observe the interaction with an&#xD;
object and verify that this interaction is in your best interest. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Scenario&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Some objects that you have to consume are just poorly written. The ones that are most&#xD;
egregious always seem to be the ones you have no control over. That lack of control&#xD;
may be because you have no access to the source, it may be because it would be a political&#xD;
minefield to change the source, or a lack of tests makes the team afraid to change&#xD;
the source. It seems like every time I go to a new client, these objects exist (as&#xD;
well as the political minefields). The developers have a mysterious set of incantations&#xD;
that they have memorized for interaction with these objects in order to avoid bugs.&#xD;
Often, no one knows where these "rules" came from and they are usually not&#xD;
written down. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Vocabulary&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The name of this pattern is the Spy. What the spy will do is capture information about&#xD;
interaction with an object, and only take action if the need arises. A spy object&#xD;
looks just like the object that you need to interact with (i.e. implements the same&#xD;
public interface) such that your code should not even notice it is even there, but,&#xD;
behind the scenes it will perform validation and give the useful feedback you wish&#xD;
the original object would have implemented in the first place. This spy or validation&#xD;
wrapper is commonly implemented by holding on to a reference to original object. This&#xD;
allows for the spy to call the actual implementation in order to preserve the original&#xD;
behavior. &#xD;
&lt;/p&gt;&#xD;
        &lt;blockquote&gt;&#xD;
          &lt;div&gt;&#xD;
            &lt;p&gt;&#xD;
              &lt;strong&gt;The ideal world&lt;/strong&gt;&#xD;
            &lt;/p&gt;&#xD;
            &lt;p&gt;&#xD;
In an ideal world, the kinds of interactions that you are trying to validate with&#xD;
a spy &lt;em&gt;should&lt;/em&gt; be captured be captured by the actual object you are interacting&#xD;
with, rather than the spy. Having a wrapper object whose function is validation is&#xD;
a massive code smell. If you have the ability to fix the original code by adding the&#xD;
relevant validation, that is by far a better solution than creating a spy object.&#xD;
&lt;/p&gt;&#xD;
            &lt;p&gt;&#xD;
              &lt;strong&gt;The real world&lt;/strong&gt;&#xD;
            &lt;/p&gt;&#xD;
            &lt;p&gt;&#xD;
In reality, you do not have access to change the source of third party libraries,&#xD;
even if sometimes that third party is a couple of buildings or even cubes away. The&#xD;
first thing you should do when you run in to these bizarre incantations “required”&#xD;
for successful object interaction, is to ask “why?” and be persistent, dig deep. You&#xD;
may be (not so) surprised that most of the reasons have long since &lt;a href="http://www.snopes.com/weddings/newlywed/secret.asp"&gt;gone&#xD;
away&lt;/a&gt;. If you do find that some of the hidden rules are indeed valid, you need&#xD;
a way to validate that your code is following the rules.&#xD;
&lt;/p&gt;&#xD;
          &lt;/div&gt;&#xD;
        &lt;/blockquote&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Example&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Consider the following example where &lt;em&gt;MethodToObserve&lt;/em&gt; will throw an uninformitive&#xD;
exception if the &lt;em&gt;PropertyToObserve&lt;/em&gt; has not yet been set. &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    1&lt;/span&gt; &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;interface&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IInterfaceToUse&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    2&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    3&lt;/span&gt;     &lt;span style="color: blue"&gt;void&lt;/span&gt; MethodToObserve();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    4&lt;/span&gt;     &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
PropertyToObserve { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    5&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    6&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    7&lt;/span&gt; &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClassToUse&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;IInterfaceToUse&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    8&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    9&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; MethodToObserve()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   10&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   11&lt;/span&gt;        &#xD;
PropertyToObserve.ForEach(str =&amp;gt;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   12&lt;/span&gt;                  &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Calling&#xD;
the MethodToObserve:"&lt;/span&gt; + str) );&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   13&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   14&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   15&lt;/span&gt;     &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
propertyToObserve;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   16&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
PropertyToObserve&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   17&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   18&lt;/span&gt;         &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   19&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   20&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine( &lt;span style="color: #a31515"&gt;"Calling&#xD;
the PropertyToObserve setter"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   21&lt;/span&gt;             &lt;span style="color: blue"&gt;return&lt;/span&gt; propertyToObserve;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   22&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   23&lt;/span&gt;         &lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   24&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   25&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Calling&#xD;
the PropertyToObserve getter"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   26&lt;/span&gt;            &#xD;
propertyToObserve = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   27&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   28&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   29&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
As mentioned previously, the ideal solution is to fix the implementation. If your&#xD;
only access to this code is Reflector or you are just not authorized to change it,&#xD;
the next best thing is to protect yourself (flaming email to the author of the code&#xD;
is,of course, optional). Our protection, or at least better information will come&#xD;
from a class implementing &lt;em&gt;IInterfaceToUse&lt;/em&gt; just like the original, only this&#xD;
time the implementation will provide the consumer with information that they can act&#xD;
on.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    1&lt;/span&gt; &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ValidatingObserver&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;IInterfaceToUse&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    2&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    3&lt;/span&gt;     &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IInterfaceToUse&lt;/span&gt; _observedClass;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    4&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    5&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt; ValidatingObserver(&lt;span style="color: #2b91af"&gt;IInterfaceToUse&lt;/span&gt; observedClass)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    6&lt;/span&gt;     {&#xD;
_observedClass = observedClass; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    7&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    8&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; MethodToObserve()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    9&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   10&lt;/span&gt;         &lt;span style="color: blue"&gt;if&lt;/span&gt; (PropertyToObserve&#xD;
== &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   11&lt;/span&gt;             &lt;span style="color: blue"&gt;throw&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"PropertyToObserve"&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   12&lt;/span&gt;                                             &lt;span style="color: #a31515"&gt;"Property&#xD;
must be set prior to calling Method"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   13&lt;/span&gt;         &lt;span style="color: green"&gt;//&#xD;
perform observations&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   14&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"The&#xD;
spy is watching: MethodToObserve"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   15&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   16&lt;/span&gt;         &lt;span style="color: green"&gt;//&#xD;
pass through to implementing object&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   17&lt;/span&gt;        &#xD;
_observedClass.MethodToObserve();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   18&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   19&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   20&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
PropertyToObserve&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   21&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   22&lt;/span&gt;         &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   23&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   24&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"The&#xD;
spy is watching: PropertyToObserve getter"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   25&lt;/span&gt;             &lt;span style="color: blue"&gt;return&lt;/span&gt; _observedClass.PropertyToObserve;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   26&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   27&lt;/span&gt;         &lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   28&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   29&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"The&#xD;
spy is watching: PropertyToObserve setter"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   30&lt;/span&gt;            &#xD;
_observedClass.PropertyToObserve = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   31&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   32&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   33&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Note that this time, instead of the “oops, I forgot something exception” known in&#xD;
.net as the “Object reference not set to instance of an object” exception, we get&#xD;
meaningful information about what is missing and even some hint as to how to fix it.&#xD;
The error now clearly states that the &lt;em&gt;PropertyToObserve&lt;/em&gt; should be set prior&#xD;
to calling the &lt;em&gt;MethodToObserve&lt;/em&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Using the spy&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There are many ways to create a spy object, I chose containment for this post; You&#xD;
may also use derivation to create your wrapper. Derivation will get you up and running&#xD;
faster, and you will not have maintenance work to do if you add a method to the interface,&#xD;
but this will come at a cost. Containment will allow you to swap out the actual implementation&#xD;
of the object with a mock implementation at some time in the future. As always consider&#xD;
you needs before choosing a spy implementation.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The test below shows how to use the spy created in this post&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    1&lt;/span&gt; [&lt;span style="color: #2b91af"&gt;TestFixture&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    2&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ManualObserverTests&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    4&lt;/span&gt;     [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    5&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; MethodCallSpy()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    6&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    7&lt;/span&gt;         &lt;span style="color: blue"&gt;var&lt;/span&gt; observedClass&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClassToUse&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    8&lt;/span&gt;         &lt;span style="color: blue"&gt;var&lt;/span&gt; validatingObserver&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ValidatingObserver&lt;/span&gt;(observedClass);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;    9&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   10&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.Throws&amp;lt;&lt;span style="color: #2b91af"&gt;ArgumentNullException&lt;/span&gt;&amp;gt;(&#xD;
validatingObserver.MethodToObserve);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   11&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   12&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Tool Support&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
All of the previous posts in this series have mentioned leveraging tools to assist&#xD;
in creating these test objects. They spy object however is a strange beast; the demands&#xD;
it places on the tools turn out to create as much code as the manually coded version.&#xD;
If you are so inclined, you can use Rhino for a spy object. What is required is taking&#xD;
advantage of the Do extension method. Do takes a delegate as a parameter that matches&#xD;
the signature of the method being called. So what you will end up establishing is&#xD;
an &lt;em&gt;Expect&lt;/em&gt;ation that a method will be called and when it is &lt;em&gt;Do&lt;/em&gt; the&#xD;
operation specified by the delegate. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Summary&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The spy object reminds me of the &lt;a href="http://www.pragprog.com/the-pragmatic-programmer/extracts/software-entropy"&gt;Broken&#xD;
Windows&lt;/a&gt; section of the &lt;a href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X/ref=sr_1_4?ie=UTF8&amp;amp;s=books&amp;amp;qid=1242740154&amp;amp;sr=8-4"&gt;Pragmatic&#xD;
Programmer&lt;/a&gt;. It clearly states not to live with broken windows, but if you cannot&#xD;
fix the window, at least put a board over the window. In the case of third party code&#xD;
where you cannot change the source code, a validation wrapper is the board you need&#xD;
to keep further damage from occurring and show other developers in the area that you&#xD;
still care about the quality of code.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;The Series&lt;/b&gt;&#xD;
          &lt;br&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting0Introduction.aspx"&gt;PatternsInTesting[0]&#xD;
- Introduction&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting1DummyPattern.aspx"&gt;PatternsInTesting[1]&#xD;
- Dummy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;a href="http://developusing.net/2008/12/10/PatternsInTesting2StubPattern.aspx"&gt;PatternsInTesting[2]&#xD;
- Stub Pattern&lt;/a&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2009/05/19/PatternsInTesting3SpyPattern.aspx"&gt;PatternsInTesting[3]&#xD;
- Spy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
PatternsInTesting[4] - Mock Pattern &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=6a0a4830-21e5-4012-a67a-51adcc156475"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=1o6KCXdTMnI:k6c8GzBlWKU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/1o6KCXdTMnI" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,6a0a4830-21e5-4012-a67a-51adcc156475.aspx</comments>
      <category>patterns</category>
      <category>programming</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2009/05/19/PatternsInTesting3SpyPattern.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=c76e2c1e-2e64-42ce-bdf6-39f7aab0784a</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,c76e2c1e-2e64-42ce-bdf6-39f7aab0784a.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,c76e2c1e-2e64-42ce-bdf6-39f7aab0784a.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c76e2c1e-2e64-42ce-bdf6-39f7aab0784a</wfw:commentRss>
      
      <title>The MX Revolution is not a presentation mouse</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,c76e2c1e-2e64-42ce-bdf6-39f7aab0784a.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/-TammbBSkMg/TheMXRevolutionIsNotAPresentationMouse.aspx</link>
      <pubDate>Thu, 19 Mar 2009 23:20:16 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://developusing.net/content/binary/WindowsLiveWriter/TheMXRevolutionisnotapresentationmouse_10F96/revolution_3_2.jpg"&gt;&#xD;
            &lt;img title="revolution_3" style="border-right: 0px; border-top: 0px; display: inline; margin-left: 0px; border-left: 0px; margin-right: 0px; border-bottom: 0px" height="177" alt="revolution_3" src="http://developusing.net/content/binary/WindowsLiveWriter/TheMXRevolutionisnotapresentationmouse_10F96/revolution_3_thumb.jpg" width="142" align="right" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;I&#xD;
love my &lt;a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16826104015"&gt;MX&#xD;
Revolution&lt;/a&gt; mouse. It is the most comfortable mouse I have used to date. For me,&#xD;
this is the first mouse that the wireless works without glitches, the scroll wheel&#xD;
has virtually no resistance, and there are a pile of programmable features on well&#xD;
placed buttons. As a desktop mouse, I would suggest anyone give it a try.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
As a presentation mouse, however, it did not work so well. The scroll wheel with no&#xD;
resistance would scroll under its own weight causing my slides to advance and back&#xD;
up in a very rapid fashion. This is a great example of a highly desired feature in&#xD;
one context being a complete hindrance in another. Now off I go to  find a device&#xD;
well suited for presentations. &#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=c76e2c1e-2e64-42ce-bdf6-39f7aab0784a"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=-TammbBSkMg:o1YmZXx7LWQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/-TammbBSkMg" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,c76e2c1e-2e64-42ce-bdf6-39f7aab0784a.aspx</comments>
      <category>hardware</category>
    <feedburner:origLink>http://developusing.net/2009/03/19/TheMXRevolutionIsNotAPresentationMouse.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=9803fb00-0e05-4ad1-b5cb-147762ec5504</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,9803fb00-0e05-4ad1-b5cb-147762ec5504.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,9803fb00-0e05-4ad1-b5cb-147762ec5504.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9803fb00-0e05-4ad1-b5cb-147762ec5504</wfw:commentRss>
      
      <title>More Patterns in Testing</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,9803fb00-0e05-4ad1-b5cb-147762ec5504.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/XGduMhoydPI/MorePatternsInTesting.aspx</link>
      <pubDate>Mon, 16 Mar 2009 17:48:40 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;I will be presenting items from the PatternsInTesting&#xD;
series as well as some additional content in the &lt;a href="http://developusing.net/2009/03/12/PatternsInTestingGoesLive.aspx"&gt;Test&#xD;
Driven is Driving me Insane&lt;/a&gt; talk at the &lt;a href="http://migang.org/MeetingInfo.aspx?CntProv=Events&amp;amp;CntItem=918abb85-b6f6-4208-a6f5-4340db63d2b3&amp;amp;ReturnURL=%2fMeetings.aspx&amp;amp;CntCatID=a0e23ee0-1ffe-4808-8aef-4316a2f458b0"&gt;Great&#xD;
Lakes .net User Group&lt;/a&gt; on 3/18/2009 and at the &lt;a href="http://www.nwnug.com/"&gt;Northwest&#xD;
Ohio .net User Group&lt;/a&gt; on 4/21/2009. This has been a really fun talk so far and&#xD;
I have enjoyed the conversation it generates. Stop by if you can make it.&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=9803fb00-0e05-4ad1-b5cb-147762ec5504"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=XGduMhoydPI:T-hAuPRW2MI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/XGduMhoydPI" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,9803fb00-0e05-4ad1-b5cb-147762ec5504.aspx</comments>
      <category>community</category>
      <category>patterns</category>
      <category>tdd</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2009/03/16/MorePatternsInTesting.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=ea980c5a-24ab-4e03-92eb-00685ad0b38b</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,ea980c5a-24ab-4e03-92eb-00685ad0b38b.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,ea980c5a-24ab-4e03-92eb-00685ad0b38b.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ea980c5a-24ab-4e03-92eb-00685ad0b38b</wfw:commentRss>
      
      <title>Patterns in testing goes live</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,ea980c5a-24ab-4e03-92eb-00685ad0b38b.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/vwS3jvo_3Gs/PatternsInTestingGoesLive.aspx</link>
      <pubDate>Thu, 12 Mar 2009 13:15:15 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I will be presenting items from the PatternsInTesting series at the &lt;a href="http://glugnet.org"&gt;Greater&#xD;
Lansing .net User Group Flint &lt;/a&gt;meeting. I was compelled to put this blog series&#xD;
and presentation together to address the pain many organization experience when trying&#xD;
to include automated testing into their development process. The content is based&#xD;
on the insight and lessons learned that I have picked up by experiencing the same&#xD;
transition in multiple organizations. Participants in this presentation will walk&#xD;
away with tools for writing more effective tests and how to better identify issues&#xD;
in tests.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=ea980c5a-24ab-4e03-92eb-00685ad0b38b"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=vwS3jvo_3Gs:1DngyeCJZtc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/vwS3jvo_3Gs" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,ea980c5a-24ab-4e03-92eb-00685ad0b38b.aspx</comments>
      <category>community</category>
      <category>patterns</category>
      <category>tdd</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2009/03/12/PatternsInTestingGoesLive.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5</wfw:commentRss>
      
      <title>PatternsInTesting[2] - Stub Pattern</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/6VgrK3DAMog/PatternsInTesting2StubPattern.aspx</link>
      <pubDate>Wed, 10 Dec 2008 22:49:06 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Scenario&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
On our continuing quest to create unit tests that exercise only the class under test,&#xD;
we look at another common scenario that occurs while writing tests. As with the &lt;i&gt;Dummy&lt;/i&gt;,&#xD;
our class under test has a dependency on another class, only this time the dependent&#xD;
class has an active role in our test. Our testing needs are about the logic of the&#xD;
class under test and not the interaction with the dependent object. In order to create&#xD;
a good test, the class under test must be isolated from the dependent object. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
An example of this scenario might look like this: &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   11&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;interface&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ICalculator&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   12&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   13&lt;/span&gt;         &lt;span style="color: blue"&gt;int&lt;/span&gt; Add(&lt;span style="color: blue"&gt;int&lt;/span&gt; left, &lt;span style="color: blue"&gt;int&lt;/span&gt; right);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   14&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   15&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Fib&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   16&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   17&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ICalculator&lt;/span&gt; _calculator;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   18&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ICalculator&lt;/span&gt; Calculator&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   19&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   20&lt;/span&gt;             &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; _calculator;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   21&lt;/span&gt;             &lt;span style="color: blue"&gt;set&lt;/span&gt; {&#xD;
_calculator = &lt;span style="color: blue"&gt;value&lt;/span&gt;;    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   22&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   23&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   24&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; Next(&lt;span style="color: blue"&gt;int&lt;/span&gt; i, &lt;span style="color: blue"&gt;int&lt;/span&gt; j)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   25&lt;/span&gt;        &#xD;
{ &lt;span style="color: blue"&gt;return&lt;/span&gt; Calculator.Add(i,j); }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   26&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The class under test in this scenario is &lt;i&gt;Fib&lt;/i&gt;, which has a dependency on an &lt;i&gt;ICalculator&lt;/i&gt;.&#xD;
The test's objective is to validate that the &lt;i&gt;Next&lt;/i&gt; method returns the correct&#xD;
result for some well-known examples.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Vocabulary&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The name of this pattern is the Stub. A stub stands in the place of the actual object&#xD;
in use and provides known answers and predictable behavior. If you are doing any sort&#xD;
of evolutionary development, chances are that the initial versions of your classes&#xD;
more resemble stubs then real code. Why? The goal is the same: you wrote stub functionality&#xD;
to allow you to focus your development efforts on different parts of the system. This&#xD;
is exactly what we are doing with Stub tests: isolate one part of the system from&#xD;
another by providing known results. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The solution without tools&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Unlike with a &lt;i&gt;Dummy&lt;/i&gt;, providing a class that throws a &lt;i&gt;NotImplementedExcpetion&lt;/i&gt; in&#xD;
the &lt;i&gt;Add&lt;/i&gt; method does not meet our needs. Since the functionality of &lt;i&gt;ICalculator&lt;/i&gt; is&#xD;
outside the scope of this test, we assume that it is working correctly (and hopefully&#xD;
under test). A simplistic implementation of &lt;i&gt;ICalculator &lt;/i&gt;will work nicely. Since&#xD;
we are not testing the calculator, provide a simplistic calculator that returns fixed&#xD;
results.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   38&lt;/span&gt;     [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   39&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; NextResultIsCorrect()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   40&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   41&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Fib&lt;/span&gt; fib&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Fib&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   42&lt;/span&gt;        &#xD;
fib.Calculator = &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;StubCalculator&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   43&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   44&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(fib.Next(2,&#xD;
3), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.EqualTo(5));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   45&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;&#xD;
            &lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   29&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;StubCalculator&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;ICalculator&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   30&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   31&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; Add(&lt;span style="color: blue"&gt;int&lt;/span&gt; left, &lt;span style="color: blue"&gt;int&lt;/span&gt; right)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   32&lt;/span&gt;        &#xD;
{ &lt;span style="color: blue"&gt;return&lt;/span&gt; 5; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   33&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The test will check that the &lt;i&gt;Next &lt;/i&gt;method returns the correct result given the &lt;i&gt;StubCalculator&lt;/i&gt;.&#xD;
What we end up doing here is fully exercising the &lt;i&gt;Fib &lt;/i&gt;class with known values&#xD;
from its dependent classes. The stub gives us the proper level of isolation for this&#xD;
test.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The solution with Rhino Mocks&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
For this version, leverage Rhino Mocks to keep us from having to code physical versions&#xD;
of the Stub class. Using Rhino's Fluent Interface, this reads as Expect a call on&#xD;
Calculator with the parameters 2 and 3, and when making this call return 5 as a result.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   47&lt;/span&gt;     [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   48&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; NextNumberIsCorrect()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   49&lt;/span&gt;     {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   50&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Fib&lt;/span&gt; fib&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Fib&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   51&lt;/span&gt;        &#xD;
fib.Calculator = &lt;span style="color: #2b91af"&gt;MockRepository&lt;/span&gt;.GenerateStub&amp;lt;&lt;span style="color: #2b91af"&gt;ICalculator&lt;/span&gt;&amp;gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   52&lt;/span&gt;        &#xD;
fib.Calculator.Expect(calc =&amp;gt; calc.Add(2, 3)).Return(5);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   53&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   54&lt;/span&gt;         &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(fib.Next(2,&#xD;
3), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.EqualTo(5));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;   55&lt;/span&gt;     }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The tools advantage&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Just as discussed with &lt;i&gt;IComplicated&lt;/i&gt; in the &lt;i&gt;Dummy &lt;/i&gt;sample, adding methods&#xD;
to &lt;i&gt;ICalculator&lt;/i&gt; does not require any additional maintenance of this test. However,&#xD;
unlike the &lt;i&gt;Dummy&lt;/i&gt; sample, calls into the stub return the expected value. Additional&#xD;
benefits can easily pile up. Consider adding multiple calls to &lt;i&gt;Add &lt;/i&gt;with different&#xD;
parameters. The hand-coded version would need some sort of conditional logic to determine&#xD;
what to return based on the calling parameters. Complexity adds up fast, even in the&#xD;
simple example listed here. Using Rhino, one concise and readable line of code can&#xD;
use new parameters for an additional expectation, including the expected result, and&#xD;
Rhino deals with matching up the parameters with the correct result. This is just&#xD;
a glimpse into the functionality offered by Rhino; the upcoming patterns will cover&#xD;
even more capability.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Isolation effects&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Should a test that checks the result of the &lt;i&gt;Next &lt;/i&gt;method fail if there is something&#xD;
wrong with the &lt;i&gt;ICalculator &lt;/i&gt;implementation? The answer, as always, is "it&#xD;
depends." This test should fail if we were writing an integration test—a test&#xD;
that ensures all the pieces of a system are working together. This test should not&#xD;
fail based on &lt;i&gt;ICalculator &lt;/i&gt;if it is a unit test, focused only on the result&#xD;
of &lt;i&gt;Next&lt;/i&gt;. Isolating &lt;i&gt;ICalculator &lt;/i&gt;from &lt;i&gt;Fib &lt;/i&gt;helps build a set of&#xD;
unit tests that can quickly identify the location of errors introduced into a system.&#xD;
The stub is a common pattern of isolation, and using it will make a marked and immediate&#xD;
improvement in your tests.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;The Series&lt;/b&gt;&#xD;
          &lt;br&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting0Introduction.aspx"&gt;PatternsInTesting[0]&#xD;
- Introduction&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting1DummyPattern.aspx"&gt;PatternsInTesting[1]&#xD;
- Dummy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/10/PatternsInTesting2StubPattern.aspx"&gt;PatternsInTesting[2]&#xD;
- Stub Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2009/05/19/PatternsInTesting3SpyPattern.aspx"&gt;PatternsInTesting[3]&#xD;
- Spy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
PatternsInTesting[4] - Mock Pattern &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=6VgrK3DAMog:RS-pJPPeI24:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/6VgrK3DAMog" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,7a8184a8-d343-4b6e-9c8d-70b95e8e9ab5.aspx</comments>
      <category>patterns</category>
      <category>programming</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2008/12/10/PatternsInTesting2StubPattern.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=21f508fe-a715-4d6c-8105-c58cd81b0a1f</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,21f508fe-a715-4d6c-8105-c58cd81b0a1f.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,21f508fe-a715-4d6c-8105-c58cd81b0a1f.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=21f508fe-a715-4d6c-8105-c58cd81b0a1f</wfw:commentRss>
      
      <title>PatternsInTesting[1] - Dummy Pattern</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,21f508fe-a715-4d6c-8105-c58cd81b0a1f.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/TCU3Vdc48I4/PatternsInTesting1DummyPattern.aspx</link>
      <pubDate>Thu, 04 Dec 2008 10:01:09 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Scenario&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
One of the characteristics of a good &lt;i&gt;unit&lt;/i&gt; test is that the object under test&#xD;
is the only object being exercised. The problem in this scenario is that the object&#xD;
under test requires a dependent object, even though the functionality of the dependent&#xD;
object is not used in the test. To make a good test, the dependent object needs to&#xD;
be isolated from the class under test. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
An example of this scenario might look like this: &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    8&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;interface&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    9&lt;/span&gt;    &#xD;
{ &lt;span style="color: blue"&gt;void&lt;/span&gt; DoStuff(); }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   10&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   11&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ClassUnderTest&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   12&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   13&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt; complicated;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   14&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;double&lt;/span&gt; circumference;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   15&lt;/span&gt;         &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#2b91af"&gt;double&lt;/font&gt; radius;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   16&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; ClassUnderTest(&lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt; externalComplicated)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   17&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   18&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt;(&#xD;
externalComplicated == &lt;span style="color: blue"&gt;null&lt;/span&gt; ) &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   19&lt;/span&gt;                 &lt;span style="color: blue"&gt;throw&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: rgb(163,21,21)"&gt;"complicated&#xD;
is required"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   20&lt;/span&gt;            &#xD;
complicated = externalComplicated; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   21&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   22&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt; DoInternalStuff() &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   23&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   24&lt;/span&gt;             &lt;span style="color: blue"&gt;return&lt;/span&gt; circumference/(2*radius);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   25&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   26&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The dependency in &lt;i&gt;ClassUnderTest&lt;/i&gt; is that its constructor requires an instance&#xD;
of an object that implements &lt;i&gt;IAmComplicated&lt;/i&gt;.&lt;i&gt;&lt;/i&gt;The rather simple objective&#xD;
of this test is to validate that DoInternalStuff returns Pi within a reasonable amount&#xD;
of rounding error.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Vocabulary&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The name of this pattern is the Dummy. It is unclear to me whether this is a reference&#xD;
to the object that enables isolation for the test or a reference to the original author&#xD;
of the code. It seems to be a code smell for this scenario to even occur. However,&#xD;
sometimes you need to use an external library and do not have liberty of changing&#xD;
the code.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The solution without tools&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Using only Visual Studio, add a class that implements &lt;i&gt;IAmComplicated&lt;/i&gt;, right-click&#xD;
on it, and choose implement interface. Every method in the class will throw a &lt;i&gt;NotImplementedException&lt;/i&gt;.&#xD;
This class meets the needs of the test because none of the methods are ever called;&#xD;
its only purpose is existence.This is your Dummy.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    1&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ComplicatedDummy&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    2&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    3&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; DoStuff()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    4&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    5&lt;/span&gt;             &lt;span style="color: blue"&gt;throw&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;NotImplementedException&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    6&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;    7&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This Dummy class allows us to create the following test: &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   39&lt;/span&gt;    &#xD;
[&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   40&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; DoStuffValidates()&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   41&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   42&lt;/span&gt;         &lt;span style="color: rgb(43,145,175)"&gt;ClassUnderTest&lt;/span&gt; cut&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ClassUnderTest&lt;/span&gt;(&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ComplicatedDummy&lt;/span&gt;());&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   43&lt;/span&gt;        &#xD;
cut.circumference = 314;&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   44&lt;/span&gt;        &#xD;
cut.radius = 50;&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   45&lt;/span&gt;         &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: rgb(43,145,175)"&gt;Math&lt;/span&gt;.PI,&#xD;
cut.DoInternalStuff(), 0.01d);&#xD;
&lt;/p&gt;&#xD;
            &lt;p style="margin: 0px"&gt;&#xD;
              &lt;span style="color: rgb(43,145,175)"&gt;   46&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;/div&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The solution with Rhino Mocks&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Rhino Mocks has the capability to create an object at runtime by reflecting the &lt;i&gt;IAmComplicated&lt;/i&gt; interface.&#xD;
This gives us the capability we need without having to maintain another class in the&#xD;
test project. Since Rhino is reflecting the interface at runtime, adding a method&#xD;
to the interface at a later date does not require changes to the test code. There&#xD;
are several different ways Rhino could give us a placeholder for &lt;i&gt;IAmComplicated&lt;/i&gt;.&#xD;
Here we will use a simple one line call to &lt;i&gt;GenerateStub&lt;/i&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   55&lt;/span&gt;     &lt;span style="color: rgb(43,145,175)"&gt;MockRepository&lt;/span&gt;.GenerateStub&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt;&amp;gt;();&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This one line saves us an entire file of maintenance, and our test only requires minor&#xD;
modification to use this technique. Place the call to Rhino as the parameter to the &lt;i&gt;ClassUnderTest&lt;/i&gt; constructor&#xD;
instead of creating a new &lt;i&gt;ComplicatedDummy&lt;/i&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   52&lt;/span&gt;        &#xD;
[&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   53&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; DoStuffValidates()      &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   55&lt;/span&gt;             &lt;span style="color: rgb(43,145,175)"&gt;ClassUnderTest&lt;/span&gt; cut&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ClassUnderTest&lt;/span&gt;(&lt;span style="color: rgb(43,145,175)"&gt;MockRepository&lt;/span&gt;.GenerateStub&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;IAmComplicated&lt;/span&gt;&amp;gt;());&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   56&lt;/span&gt;            &#xD;
cut.circumference = 314;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   57&lt;/span&gt;            &#xD;
cut.radius = 50;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   58&lt;/span&gt;             &lt;span style="color: rgb(43,145,175)"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: rgb(43,145,175)"&gt;Math&lt;/span&gt;.PI,&#xD;
cut.DoInternalStuff(), 0.01d);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: rgb(43,145,175)"&gt;   59&lt;/span&gt;        &#xD;
}       &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Isolation of Failure&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
One of the primary goals of good unit tests is to identify exactly which unit caused&#xD;
the error. By applying this pattern, tests that cover &lt;i&gt;ClassUnderTest&lt;/i&gt; no longer&#xD;
require an implementation of &lt;i&gt;IAmComplicated&lt;/i&gt; to instantiate without failure.&#xD;
This helps shorten your bug hunting cycle by reducing the areas that indicate error&#xD;
to where the real error occurred. As you attain higher levels of isolation and better&#xD;
definition of units, you will find you spend much less time in the debugger. This&#xD;
means spending less time finding problems more time fixing them.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;The Series&lt;/b&gt;&#xD;
          &lt;br&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting0Introduction.aspx"&gt;PatternsInTesting[0]&#xD;
- Introduction&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting1DummyPattern.aspx"&gt;PatternsInTesting[1]&#xD;
- Dummy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;a href="http://developusing.net/2008/12/10/PatternsInTesting2StubPattern.aspx"&gt;PatternsInTesting[2]&#xD;
- Stub Pattern&lt;/a&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2009/05/19/PatternsInTesting3SpyPattern.aspx"&gt;PatternsInTesting[3]&#xD;
- Spy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
PatternsInTesting[4] - Mock Pattern &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=21f508fe-a715-4d6c-8105-c58cd81b0a1f"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=TCU3Vdc48I4:icEsCPuVfrI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/TCU3Vdc48I4" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,21f508fe-a715-4d6c-8105-c58cd81b0a1f.aspx</comments>
      <category>patterns</category>
      <category>programming</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2008/12/04/PatternsInTesting1DummyPattern.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=ba591026-21f9-451e-ae23-76d401194b36</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,ba591026-21f9-451e-ae23-76d401194b36.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,ba591026-21f9-451e-ae23-76d401194b36.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ba591026-21f9-451e-ae23-76d401194b36</wfw:commentRss>
      
      <title>PatternsInTesting[0] - Introduction</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,ba591026-21f9-451e-ae23-76d401194b36.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/pSXNn4Kg7bw/PatternsInTesting0Introduction.aspx</link>
      <pubDate>Thu, 04 Dec 2008 03:05:47 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
It does not matter if your test philosophy is Test Driven Development, Test Eventually&#xD;
Development, or I write tests occasionally. Very early in your testing experience,&#xD;
you will want to start isolating portions of your application or libraries. Without&#xD;
this isolation, you will start seeing a fragile set of tests that make it challenging&#xD;
to track down the point of failure. In order to reach the level of isolation that&#xD;
your tests need, you will need to introduce Mocks (or Test Doubles) to your testing&#xD;
toolbox.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Testing Story&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Someone on your team (extra geek cred if it was you) brings the concept of adding&#xD;
tests to the development process. No doubt there is some confusion at first. What&#xD;
are tests? How do we write them? This phase quickly passes as the team finds things&#xD;
that they understand how to test. This initial period of enlightenment yields great&#xD;
results. Everyone is happy that code is doing what it should be doing. Occasionally,&#xD;
the team celebrates when a broken test flags an unintended change. Clearly development&#xD;
will never be the same again. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
As time goes on and the test library gets larger, you start to notice that a breaking&#xD;
change often causes quite a few tests to fail. The team finds this annoying, but decides&#xD;
having tests is better than developer life before tests. At some point though, the&#xD;
tests start to feel burdensome. Adding simple changes start to propagate through the&#xD;
whole system of tests. Discouragement and discontentment set in, and some of your&#xD;
team members want to abandon developing with tests. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Enter Mocks&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
At this point, the prominent options are to ignore the tests (the blue pill) or find&#xD;
a way to make the tests better (the red pill). This series will cover some of the&#xD;
test development patterns used to isolate areas of your code in the hopes that you&#xD;
will choose the red pill. The goal for the initial four or five posts will be to cover&#xD;
the types of scenarios that occur in test code and what common solutions look like.&#xD;
After that, I hope to cover some of the patterns for dealing with legacy code as I&#xD;
am currently reading through Working Effectively with Legacy Code and it seems relevant&#xD;
to the client I am working with.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;The Mock Controversy&lt;/b&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There has been considerable conversation in the community about the usage of the term &lt;i&gt;mock&lt;/i&gt;.&#xD;
Some prominent members of the development community have been pushing for changing&#xD;
the vocabulary to &lt;i&gt;test doubles&lt;/i&gt;, where &lt;i&gt;mock&lt;/i&gt;, &lt;i&gt;stub&lt;/i&gt;, &lt;i&gt;fake&lt;/i&gt; and &lt;i&gt;spy&lt;/i&gt; are&#xD;
a particular type of &lt;i&gt;test double&lt;/i&gt;s. My take on this is that these &lt;i&gt;test double&lt;/i&gt; types&#xD;
are each describing the scenario where it is useful and the technique for solving&#xD;
the problem; this is describing a pattern. Good names are the key to effective patterns,&#xD;
and we have a good set of names for pattern description. It really does not matter&#xD;
what you call the concept (&lt;i&gt;mocking&lt;/i&gt; | &lt;i&gt;doubling&lt;/i&gt; | &lt;i&gt;faking | test doubles&lt;/i&gt;)&#xD;
if the pattern names describe the scenario effectively. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;What's next?&lt;/b&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This Series of posts will explore these test double patterns and decompose a few alternate&#xD;
implementations. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;b&gt;The Series&lt;/b&gt;&#xD;
          &lt;br&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting0Introduction.aspx"&gt;PatternsInTesting[0]&#xD;
- Introduction&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/04/PatternsInTesting1DummyPattern.aspx"&gt;PatternsInTesting[1]&#xD;
- Dummy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2008/12/10/PatternsInTesting2StubPattern.aspx"&gt;PatternsInTesting[2]&#xD;
- Stub Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;a href="http://developusing.net/2009/05/19/PatternsInTesting3SpyPattern.aspx"&gt;PatternsInTesting[3]&#xD;
- Spy Pattern&lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;PatternsInTesting[4] - Mock Pattern&#xD;
&lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=ba591026-21f9-451e-ae23-76d401194b36"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=pSXNn4Kg7bw:6lzpg2ejiAI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/pSXNn4Kg7bw" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,ba591026-21f9-451e-ae23-76d401194b36.aspx</comments>
      <category>patterns</category>
      <category>programming</category>
      <category>testing</category>
    <feedburner:origLink>http://developusing.net/2008/12/04/PatternsInTesting0Introduction.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=0cafcadb-b6e2-4259-82ff-b7d0f010fe92</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,0cafcadb-b6e2-4259-82ff-b7d0f010fe92.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,0cafcadb-b6e2-4259-82ff-b7d0f010fe92.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0cafcadb-b6e2-4259-82ff-b7d0f010fe92</wfw:commentRss>
      
      <title>New features in NUnit 2.5</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,0cafcadb-b6e2-4259-82ff-b7d0f010fe92.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/Hhx4C1MLU3Y/NewFeaturesInNUnit25.aspx</link>
      <pubDate>Mon, 17 Nov 2008 03:04:37 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
In my last &lt;a href="http://developusing.net/2008/11/03/HelpIHaveTooManyPermutationsToTest.aspx"&gt;post&lt;/a&gt;,&#xD;
I mentioned the new &lt;em&gt;ValuesAttribute&lt;/em&gt; that can be used as a test factory to&#xD;
generate a series of tests with many permutations of parameters. Looking into that&#xD;
feature led me to look at the feature set in &lt;a href="http://www.nunit.org/index.php?p=home"&gt;NUnit&#xD;
2.5&lt;/a&gt; which is currently in Alpha 4. Some of these features address scenarios that&#xD;
I have run into in my test code. I wanted to mention them here so others could start&#xD;
benefiting as well.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The source of the new feature set that I am pulling from is the current &lt;a href="http://nunit.org/index.php?p=releaseNotes&amp;amp;r=2.5"&gt;release&#xD;
notes&lt;/a&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Movin' on up&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
One of the items that I think is most important &lt;strong&gt;is not&lt;/strong&gt; a new feature,&#xD;
just a change in location. The change in mind set is what stands out as important&#xD;
to me. The &lt;em&gt;Is&lt;/em&gt;, &lt;em&gt;Has&lt;/em&gt;, &lt;em&gt;Text&lt;/em&gt;, and &lt;em&gt;List&lt;/em&gt; constraints&#xD;
have been moved into the &lt;em&gt;NUnit.Framework&lt;/em&gt; namespace. They were formerly off&#xD;
in the more obscure &lt;em&gt;NUnit.Framework.SyntaxHelpers&lt;/em&gt; namespace. The assertions&#xD;
that are created using these constraints line up much better with BDD and have a more&#xD;
readable feel to them. I am happy to see them becoming part of the mainstream namespace.&#xD;
If you are not familiar with the constraint model, check out code below. &#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;&#xD;
          &lt;span style="color: green"&gt;// Classic model &lt;/span&gt;&#xD;
          &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(expected,&#xD;
actual); &lt;span style="color: green"&gt;// Constraint model &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(actual, &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.EqualTo(expected)); &lt;/pre&gt;&#xD;
        &lt;a href="http://11011.net/software/vspaste"&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
I think the second reads much more like the English phrase that the constraint would&#xD;
represent. Check out the docs; you will find that almost everything you can do with&#xD;
the "classic" model can also be done in the constraint model.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Chained Setup and TearDown&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Test code should be crafted with the same level of care as production intent code.&#xD;
This means that it should be DRY and carefully designed. Many times you will be testing&#xD;
a related set of classes, leading to base classes in your test code. Don't be afraid&#xD;
to capture common test code functionality in base classes. Prior to this release,&#xD;
the &lt;em&gt;Setup&lt;/em&gt; and &lt;em&gt;TearDown&lt;/em&gt; attributes could be applied in your base&#xD;
class, but if you applied the &lt;em&gt;Setup&lt;/em&gt; or &lt;em&gt;Teardown&lt;/em&gt; attributes in your&#xD;
derived class, the calls were not chained. You had to remember to call the base class&#xD;
version from the derived class. In 2.5, the base &lt;em&gt;Setup&lt;/em&gt; method will be call&#xD;
prior to the derived &lt;em&gt;Setup&lt;/em&gt; method by the framework. One more win for automation&#xD;
versus developer discipline. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;New constraints&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://srtsolutions.com/blogs/chrismarinos/"&gt;Chris Marinos&lt;/a&gt; recently &lt;a href="http://srtsolutions.com/blogs/chrismarinos/archive/2008/11/03/somebody-call-the-orkin-man.aspx"&gt;blogged&lt;/a&gt; about&#xD;
disliking the [ExpectedException] style of tests and wrote a helper class to support&#xD;
the syntax of &lt;em&gt;Throws.Exception&lt;/em&gt;. As of the 2.5 release &lt;em&gt;Throws.Exception&lt;/em&gt; is&#xD;
included. This allows for much more focused testing. Putting the &lt;em&gt;ExpectedExceptionAttribute&lt;/em&gt; on&#xD;
a method simply says that somewhere in the method the exception will get thrown. The&#xD;
exception may well be thrown 2 lines prior to the call you were intending to test.&#xD;
This yields a false positive test result. &lt;em&gt;Throws.Exception&lt;/em&gt; (and its set of&#xD;
related Throws) takes a delegate so that you can check a specific call for the presence&#xD;
of an exception. &#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] [&lt;span style="color: #2b91af"&gt;ExpectedException&lt;/span&gt;] &lt;span style="color: blue"&gt;public&#xD;
void &lt;/span&gt;PassesButShouldnt() { &lt;span style="color: blue"&gt;int &lt;/span&gt;importantPreWork&#xD;
= &lt;span style="color: blue"&gt;int&lt;/span&gt;.Parse(&lt;span style="color: #a31515"&gt;"abcd"&lt;/span&gt;);&#xD;
DoStuff(); } [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public&#xD;
void &lt;/span&gt;FailsProperly() { &lt;span style="color: blue"&gt;int &lt;/span&gt;importantPreWork&#xD;
= &lt;span style="color: blue"&gt;int&lt;/span&gt;.Parse(&lt;span style="color: #a31515"&gt;"abcd"&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.Throws&amp;lt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;&amp;gt;(&#xD;
DoStuff ); } &lt;span style="color: blue"&gt;public void &lt;/span&gt;DoStuff() { &lt;span style="color: blue"&gt;throw&#xD;
new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Something&#xD;
is terribly wrong"&lt;/span&gt;); } &lt;/pre&gt;&#xD;
        &lt;p&gt;&#xD;
In the example, the &lt;em&gt;PassesButShouldnt&lt;/em&gt; test passes due to the expected exception&#xD;
being thrown on the &lt;em&gt;Parse&lt;/em&gt; call. Unfortunately, the test was intended to ensure&#xD;
that &lt;em&gt;DoBadStuff&lt;/em&gt; threw an exception. The &lt;em&gt;FailsProperly&lt;/em&gt; test more&#xD;
accurately checks that only the &lt;em&gt;DoBadStuff&lt;/em&gt; call throws an exception. In addition,&#xD;
it also reads better as it places the constraint on the same line as the call just&#xD;
like any other &lt;em&gt;Assert&lt;/em&gt; method.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Attribute testing&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
With the &lt;em&gt;Has.Attribute&lt;/em&gt; constraint, you can verify an object (yes, object&#xD;
not class) is decorated with an attribute. A common example of where this could be&#xD;
used is validating that a class has been marked with the &lt;em&gt;SerializableAttribute&lt;/em&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;] &lt;span style="color: blue"&gt;public&#xD;
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;testclass &lt;/span&gt;{} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public&#xD;
void &lt;/span&gt;Test() { Assert.That(&lt;span style="color: blue"&gt;new &lt;/span&gt;testclass(),&#xD;
Has.Attribute&amp;lt;SerializableAttribute&amp;gt;()); }&lt;/pre&gt;&#xD;
        &lt;a href="http://11011.net/software/vspaste"&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
I have to admit, when I first saw the Has.Attribute constraint, I thought for sure&#xD;
one of my test base classes was going to get a bit lighter. One of the applications&#xD;
that I work on has a pluggable architecture and uses attributes to determine what&#xD;
should be exposed to the end user. I had to code up a method that used reflection&#xD;
to determine if the items that were supposed to be exposed did in fact contain the&#xD;
attribute that exposed them. I was somewhat disappointed to see that it only seemed&#xD;
to work with instances of objects and not &lt;em&gt;Type&lt;/em&gt;s or &lt;em&gt;MemberInfo&lt;/em&gt;s.&#xD;
This did get me thinking, however, that my approach of putting this in a base class&#xD;
may not have been as elegant as learning about extending NUnit. Perhaps that will&#xD;
be a post in the future. I should call out that this was in the NUnit blog as a feature&#xD;
added in Alpha 1, however, it is the only feature listed here that has not made it&#xD;
to the documentation yet. That could mean that it just has not been documented yet,&#xD;
or it could indicate that it is not yet ready for prime time.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Range Testing&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;em&gt;Is.InRange&lt;/em&gt; allows you to use a more concise syntax for expressing assertions&#xD;
that required both a &lt;em&gt;GreaterThan&lt;/em&gt; and &lt;em&gt;LessThan&lt;/em&gt; for validating an&#xD;
item is within bounds. &#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public&#xD;
void &lt;/span&gt;RangeTesting() { &lt;span style="color: green"&gt;// old way &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(3, &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.GreaterThanOrEqualTo(1)&#xD;
&amp;amp; &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.LessThanOrEqualTo(5)); &lt;span style="color: green"&gt;//&#xD;
new way &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(3, &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.InRange(1,&#xD;
5)); &lt;span style="color: green"&gt;// NOTE: InRange is inclusive &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(5, &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.InRange(1,&#xD;
5)); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(1, &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.InRange(1,&#xD;
5)); }&lt;/pre&gt;&#xD;
        &lt;a href="http://11011.net/software/vspaste"&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;New Assertions&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In some tests you are able to determine early in the test that the expected behavior&#xD;
has been met. Rather than throwing in a &lt;em&gt;return&lt;/em&gt; statement or creating triangular&#xD;
code, the new &lt;em&gt;Assert.Pass&lt;/em&gt; method is available for early termination with&#xD;
passing results. There is also a new inconclusive result state that can be set by&#xD;
calling &lt;em&gt;Assert.Inconclusive&lt;/em&gt;. I have no idea how this can be used; I cannot&#xD;
think of any test scenarios that I have had to implement where I really was looking&#xD;
for "Assert...oh...I don't know." It seems there is a failure in the system at this&#xD;
point, even if that failure point is not understanding the requirements. I would take&#xD;
this as an indicator to go clarify requirements with the client and write a better&#xD;
test.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Specialized Assertions&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;em&gt;CollectionAssert&lt;/em&gt; has picked up a set of &lt;em&gt;IsOrdered&lt;/em&gt; constraints. This&#xD;
constraint uses the &lt;em&gt;IComparable&lt;/em&gt; interface to verify increasing or decreasing&#xD;
order of all of the items in a collection. This is another one of those features that&#xD;
I have implemented in a test utilities class. I am happy to remove those lines of&#xD;
code.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Previous versions of NUnit had a &lt;em&gt;FileAssert&lt;/em&gt; class to verify that your application&#xD;
was generating an output file. &lt;em&gt;DirectoryAssert&lt;/em&gt; has been added as a compliment&#xD;
to &lt;em&gt;FileAssert&lt;/em&gt;. The &lt;em&gt;DirectoryAssert.IsWithin&lt;/em&gt; method (or &lt;em&gt;IsNotWithin&lt;/em&gt;)&#xD;
will crawl from the directory specified, including all of its subdirectories, to verify&#xD;
that the expected directory is present. You can also use &lt;em&gt;IsEmpty&lt;/em&gt; to verify&#xD;
if a file was output. You are, of course, still responsible for determining that the&#xD;
correct output was written.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Generic Support&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There are several type constraints in NUnit that take &lt;em&gt;typeof(class)&lt;/em&gt; as a&#xD;
parameter. The following constraints have been updated to include a version that takes&#xD;
a generic parameter specifying the type.&#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;&#xD;
          &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsInstanceOf&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;object &lt;/span&gt;actual); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsNotInstanceOf&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;object &lt;/span&gt;actual); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsAssignableFrom&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;object &lt;/span&gt;actual); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsNotAssignableFrom&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;object &lt;/span&gt;actual); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.Throws&amp;lt;T&amp;gt;(TypeSnippet&#xD;
code); &lt;/pre&gt;&#xD;
        &lt;a href="http://11011.net/software/vspaste"&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
The &lt;em&gt;TestFixtureAttribute&lt;/em&gt; also picked up a generic version. Use this to test&#xD;
a class that takes a generic type parameter. Specify this attribute multiple times&#xD;
on a class, each time specifying a different type for the generic parameter. For each&#xD;
type specification, a new test instance is created and executed. This is useful when&#xD;
you were trying to exercise a class under test with a couple of different types. It&#xD;
does seem like this is the wrong level of abstraction for a test, but I am sure it&#xD;
is a reaction to some level of demand.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Try it out&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Every one has a different tolerance for using things that have not been marked as&#xD;
released, yet. Early releases of NUnit traditionally have been very solid. Much like&#xD;
GMail still being in beta, it seems the open source community drop releases much more&#xD;
often, but keeps them flagged with alpha and beta. I have already started using these&#xD;
features to produce cleaner, more readable test code.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=0cafcadb-b6e2-4259-82ff-b7d0f010fe92"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=Hhx4C1MLU3Y:x8fPgZ4xWfk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/Hhx4C1MLU3Y" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,0cafcadb-b6e2-4259-82ff-b7d0f010fe92.aspx</comments>
      <category>tdd</category>
    <feedburner:origLink>http://developusing.net/2008/11/17/NewFeaturesInNUnit25.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=2b27fc5a-9414-4261-b5cb-284ac9466fac</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,2b27fc5a-9414-4261-b5cb-284ac9466fac.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,2b27fc5a-9414-4261-b5cb-284ac9466fac.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=2b27fc5a-9414-4261-b5cb-284ac9466fac</wfw:commentRss>
      
      <title>Help, I have too many permutations to test!</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,2b27fc5a-9414-4261-b5cb-284ac9466fac.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/m00UFJ_jqUQ/HelpIHaveTooManyPermutationsToTest.aspx</link>
      <pubDate>Mon, 03 Nov 2008 15:15:32 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
RowTests are a great tool for consolidating tests that have the same logic, but differ&#xD;
by the parameters and the expected values. I did &lt;a href="http://developusing.net/2008/01/16/ParameterizedTests.aspx"&gt;a&#xD;
post&lt;/a&gt; a while back on using RowTest in MbUnit, and &lt;a href="http://michaeleatonconsulting.com/blog/"&gt;Michael&#xD;
Eaton&lt;/a&gt; recently &lt;a href="http://michaeleatonconsulting.com/blog/archive/2008/11/03/getting-started-with-nunits-rowtest.aspx"&gt;posted&lt;/a&gt; on&#xD;
using RowTest with NUnit. Reading Eaton's post reminded me that I had just run into&#xD;
a new feature in the NUnit 2.5 drop. One of my favorite features of competitive open&#xD;
source tools is that they usually add at least one feature more than the other guy&#xD;
with each release. For the 2.5 release of NUnit, one of those features is the ValuesAttribute.&#xD;
Granted, MbUnit had this feature in concept with CombinationalTestAttribute, but the&#xD;
usage of the ValuesAttribute in NUnit seems much cleaner to me.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Tests with no [Values]&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Looking at the previous posts on RowTests, you can see that passing in many values&#xD;
for a specific test is not that difficult. So why would we need anything else? In&#xD;
certain scenarios, the number of permutations that you would have to write Row attributes&#xD;
for could be pretty cumbersome, and if it is truly a permutation scenario, difficult&#xD;
to maintain. The test case for this post will be that the test should be called with&#xD;
all possible combinations of 1,2,3 for one parameter and 10,20,30 for another parameter.&#xD;
With this simple example you can see that we have already blown up to 9 rows, adding&#xD;
on more variant onto either of the parameters and we would have 12 rows to maintain. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Giving your tests [Values]&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
What the values attribute does is allow you to express all 9 of these combinations&#xD;
in a very concise syntax. This lines up better with the expression of your requirements;&#xD;
instead of 9 Row attributes, you would now have the following:&#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="code"&gt;[&lt;span style="COLOR: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="COLOR: blue"&gt;public&#xD;
void &lt;/span&gt;Use_Value_Attributes([&lt;span style="COLOR: #2b91af"&gt;Values&lt;/span&gt;(1,2,3)] &lt;span style="COLOR: blue"&gt;int &lt;/span&gt;param1,[&lt;span style="COLOR: #2b91af"&gt;Values&lt;/span&gt;(10,20,30)] &lt;span style="COLOR: blue"&gt;int &lt;/span&gt;param2)&#xD;
{ r.DoStuffWithParms(param1, param2); }&lt;/pre&gt;&#xD;
        &lt;a href="http://11011.net/software/vspaste"&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
This nicely wraps up in one line what would have been expressed with 9 [Row] attributes&#xD;
in the past. Bring this up in the NUnit gui to verify that the tests you were looking&#xD;
for were in fact generated.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://developusing.net/content/binary/WindowsLiveWriter/Toomanypermutationstotest_80F6/ValueAttributes_2.png"&gt;&#xD;
            &lt;img style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height="206" alt="ValueAttributes" src="http://developusing.net/content/binary/WindowsLiveWriter/Toomanypermutationstotest_80F6/ValueAttributes_thumb.png" width="244" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;What do you use it for&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now that you have such a powerful tool in you toolset, start to think about how this&#xD;
would be useful. The real world case where I use this feature ensures that interaction&#xD;
with an external library is correct both in number and order of calls when the actual&#xD;
parameters from the system are applied. This test is purely focused on the behavior&#xD;
of the system not the expectation of a mathematical result.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;What wouldn't you use it for&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
It would be very difficult to tie an expected value to the generated permutations.&#xD;
So if you are going after a specific output from an algorithm, a RowTest will work&#xD;
much better for you. Keep in mind that the RowTest feature has been around a while,&#xD;
so it is likely that you will use it more often.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=2b27fc5a-9414-4261-b5cb-284ac9466fac"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=m00UFJ_jqUQ:OYYLS0pXww8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/m00UFJ_jqUQ" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,2b27fc5a-9414-4261-b5cb-284ac9466fac.aspx</comments>
      <category>programming</category>
      <category>tdd</category>
    <feedburner:origLink>http://developusing.net/2008/11/03/HelpIHaveTooManyPermutationsToTest.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://developusing.net/Trackback.aspx?guid=3d2f945a-1f01-419b-9bc7-d5d2ae46dc38</trackback:ping>
      <pingback:server>http://developusing.net/pingback.aspx</pingback:server>
      <pingback:target>http://developusing.net/PermaLink,guid,3d2f945a-1f01-419b-9bc7-d5d2ae46dc38.aspx</pingback:target>
      <dc:creator>Dennis Burton</dc:creator>
      <wfw:comment>http://developusing.net/CommentView,guid,3d2f945a-1f01-419b-9bc7-d5d2ae46dc38.aspx</wfw:comment>
      <wfw:commentRss>http://developusing.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3d2f945a-1f01-419b-9bc7-d5d2ae46dc38</wfw:commentRss>
      
      <title>Watch the PDC Keynote locally</title>
      <guid isPermaLink="false">http://developusing.net/PermaLink,guid,3d2f945a-1f01-419b-9bc7-d5d2ae46dc38.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevelopUsingdotnet/~3/tA3QrM0hGTw/WatchThePDCKeynoteLocally.aspx</link>
      <pubDate>Mon, 20 Oct 2008 17:16:07 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;The keynotes from &lt;a href="http://www.microsoftpdc.com/"&gt;PDC &lt;/a&gt;are&#xD;
always packed with information on the direction of tools from Redmond over the next&#xD;
couple years. If you are not going, you may be thinking, "I will download the videos&#xD;
when they are available." This year there is a better option. Join us at the &lt;a href="http://srtsolutions.com/"&gt;SRT&lt;/a&gt; offices&#xD;
in Ann Arbor. After the keynotes, and realistically during, talk with developers in&#xD;
the local community for an even better understanding of the impact of these announcements.&#xD;
Microsoft will be sponsoring lunch for this event.&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;&lt;div&gt;&lt;b&gt;Remote Viewing &amp;amp; Discussion of the Ray Ozzie Keynotes&lt;/b&gt;&lt;br&gt;&#xD;
Monday, October 27, 11:30a-2:00p - &lt;a href="http://pdcsrtsolutions.eventbrite.com/"&gt;Register&lt;/a&gt;&lt;br&gt;&#xD;
Tuesday, October 28, 11:30a-2:00p - &lt;a href="http://pdc2srtsolutions.eventbrite.com/"&gt;Register&lt;/a&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;SRT Solutions&lt;br&gt;&#xD;
206 S. Fifth Avenue, Suite 200&lt;br&gt;&#xD;
Ann Arbor, Michigan 48104&#xD;
&lt;/div&gt;&lt;/blockquote&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://developusing.net/aggbug.ashx?id=3d2f945a-1f01-419b-9bc7-d5d2ae46dc38"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?a=tA3QrM0hGTw:jM3zLmQgh7I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevelopUsingdotnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevelopUsingdotnet/~4/tA3QrM0hGTw" height="1" width="1"/&gt;</description>
      <comments>http://developusing.net/CommentView,guid,3d2f945a-1f01-419b-9bc7-d5d2ae46dc38.aspx</comments>
      <category>community</category>
    <feedburner:origLink>http://developusing.net/2008/10/20/WatchThePDCKeynoteLocally.aspx</feedburner:origLink></item>
  </channel>
</rss>
