<?xml version="1.0" encoding="utf-8"?>
<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/" version="2.0">
  <channel>
    <title>Peli's Farm - Pex, Stubs, Moles, QuickGraph, MbUnit, Reflector Addins - Stubs</title>
    <link>http://blog.dotnetwiki.org/</link>
    <description>TouchDevelop, Pex4Fun, Rise4Fun, Pex, Moles, QuickGraph, MbUnit, Reflector Addins</description>
    <language>en-us</language>
    <copyright>Jonathan 'Peli' de Halleux</copyright>
    <lastBuildDate>Sat, 30 Jan 2010 05:48:59 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>jonathan.dehalleux@gmail.com</managingEditor>
    <webMaster>jonathan.dehalleux@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=2723489d-602b-4303-bb40-5a58a90b2573</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,2723489d-602b-4303-bb40-5a58a90b2573.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,2723489d-602b-4303-bb40-5a58a90b2573.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=2723489d-602b-4303-bb40-5a58a90b2573</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just released a new version of <a href="http://research.microsoft.com/pex/">Pex
and Moles</a> that brings a number of bug fixes and various improvements to the behaviors
for SharePoint and Asp.NET.
</p>
        <p>
          <strong>Improvements</strong>
        </p>
        <ul>
          <li>
Interaction with the Source Control provider has been significantly improved for Moles 
</li>
          <li>
Support for Moles of nested types. 
</li>
          <li>
Improved logging in the Host Type 
</li>
          <li>
Improved Behaved collections 
</li>
          <li>
Added Behaved types for mscorlib and System.Web types.</li>
        </ul>
        <p>
          <strong>Bug fixes</strong>
        </p>
        <ul>
          <li>
Updated several outdated section in the documentation 
</li>
          <li>
Updated missing classes in the SharePoint samples 
</li>
          <li>
Fixed a limitation of the profiler that would silently fail to instrument certain
methods</li>
        </ul>
        <p>
          <strong>Breaking Changes</strong>
        </p>
        <ul>
          <li>
We have formalized the naming convention of Moles and Stubs and found some holes along
the way. Some mole method might have a new name under this version of the compiler.</li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=2723489d-602b-4303-bb40-5a58a90b2573" />
      </body>
      <title>Pex v0.22.50128.1: Bug fixes, bug fixes, bug fixes</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,2723489d-602b-4303-bb40-5a58a90b2573.aspx</guid>
      <link>http://blog.dotnetwiki.org/2010/01/30/PexV022501281BugFixesBugFixesBugFixes.aspx</link>
      <pubDate>Sat, 30 Jan 2010 05:48:59 GMT</pubDate>
      <description>&lt;p&gt;
We just released a new version of &lt;a href="http://research.microsoft.com/pex/"&gt;Pex
and Moles&lt;/a&gt; that brings a number of bug fixes and various improvements to the behaviors
for SharePoint and Asp.NET.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Improvements&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Interaction with the Source Control provider has been significantly improved for Moles 
&lt;li&gt;
Support for Moles of nested types. 
&lt;li&gt;
Improved logging in the Host Type 
&lt;li&gt;
Improved Behaved collections 
&lt;li&gt;
Added Behaved types for mscorlib and System.Web types.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Bug fixes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Updated several outdated section in the documentation 
&lt;li&gt;
Updated missing classes in the SharePoint samples 
&lt;li&gt;
Fixed a limitation of the profiler that would silently fail to instrument certain
methods&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Breaking Changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
We have formalized the naming convention of Moles and Stubs and found some holes along
the way. Some mole method might have a new name under this version of the compiler.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=2723489d-602b-4303-bb40-5a58a90b2573" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,2723489d-602b-4303-bb40-5a58a90b2573.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=ec9069cd-89d0-4958-9894-e792aeda0abc</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,ec9069cd-89d0-4958-9894-e792aeda0abc.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,ec9069cd-89d0-4958-9894-e792aeda0abc.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=ec9069cd-89d0-4958-9894-e792aeda0abc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx">released
Pex 0.21.50115.2</a>. This release brings bug fixes, a big renaming from “Stubs” to
“Moles” and improved infrastructure to build behaved types (formerly known as beavers).
</p>
        <p>
          <strong>Bug Fixes</strong>
        </p>
        <ul>
          <li>
The Moles VsHost fails to execute unit tests in different assemblies. 
</li>
          <li>
            <a href="http://research.microsoft.com/pex/">Pex</a> deletes the report folder it
is currently writing to. 
</li>
          <li>
Support for named indexers in Stubs 
</li>
          <li>
Fixed bugs in how Pex reasons about System.Convert.ToBase64, DateTime 
</li>
          <li>
Invalid support for protected members in the stubs generation</li>
        </ul>
        <p>
          <strong>Breaking changes</strong>
        </p>
        <ul>
          <li>
            <strong>The Stubs framework was renamed to Moles framework.</strong> We have decided
to make the Moles the center of the framework and as a consequence, renamed ‘Stubs’
to ‘Moles’. (This does not mean that we encourage writing untestable code, as Mole
help to make it testable. You should still refactor your code to make it testable
whenever possible, and only use Moles when that’s the only choice). The impact is
that 
<ul><li>
Microsoft.Stubs.Framework was renamed to Microsoft.Moles.Framework 
</li><li>
The moles and stubs get generated in subnamespaces ‘.Moles’ rather ‘.Stubs’. 
</li><li>
See below for the list of steps to upgrade your applications.</li></ul></li>
          <li>
            <strong>BaseMembers in Moles have been deprecated</strong>: this helper is not useful
as it can be acheive in a better way through a constructor. We decided to remove it
to reduce code size. The second reason is that BaseMembers would only work for types
inside of the same assembly, which might seem inconsistent. 
</li>
          <li>
            <strong>PexGoal.Reached is replaced by PexAssert.ReachEventually().</strong> The PexGoal
class has been integrated into PexAssert through the ReachEventually method which
should be used with the [PexAssertReachEventually] attribute. 
</li>
          <li>
            <strong>PexChoose simplified</strong>: we’ve simplified the PexChoose API; you can
now get auxiliary test inputs with a single method call: PexChoose.Value&lt;T&gt;(“foo”).</li>
        </ul>
        <p>
          <strong>Migrating from previous version of Pex</strong>
        </p>
        <p>
Since we’ve renamed Stubs to Moles, any existing .stubx files will not work anymore.
</p>
        <p>
Take a deep breath, and apply the following steps to adapt your projects:
</p>
        <ul>
          <li>
change the project reference from Microsoft.Stubs.Framework.dll to Microsoft.Moles.Framework.dll 
</li>
          <li>
rename all .stubx files to .moles, and 
<ul><li>
rename the top <strong>&lt;Stubs</strong> xml element to <strong>&lt;Moles</strong>. 
</li><li>
Change the XSD namespace to <a href="http://schemas.microsoft.com/moles/2010/">http://schemas.microsoft.com/moles/2010/</a></li><li>
Right click on the .moles file in the Solution Explorer and change the Custom Tool
Name to ‘MolesGenerator’. 
</li><li>
Delete all the nested files under the .moles files</li></ul></li>
          <li>
Remove references to any compiled .Stubs.dll files in your project 
</li>
          <li>
In general, remove all .Stubs.dll, .Stubs.xml files from your projects. 
</li>
          <li>
Rename .Stubs namespace suffixes to .Moles. 
</li>
          <li>
replace all [HostType(“Pex”)] attribute with [HostType(“Moles”)] 
</li>
          <li>
in PexAssemblyInfo.cs, 
<ul><li>
rename using Microsoft.Pex.Framework.Stubs to Microsoft.Pex.Framework.Moles 
</li><li>
rename [assembly: PexChooseAsStubFallbackBehavior] to [assembly: PexChooseAsBehavedCurrentBehavior] 
</li><li>
rename [assembly: PexChooseAsStubFallbackBehavior] to [assembly: PexChooseAsMoleCurrentBehavior]</li></ul></li>
          <li>
In general, the ‘Fallback’ prefix has been dropped in the following methods: 
<ul><li>
rename FallbackAsNotImplemented() to BehaveAsNotImplemented() 
</li><li>
rename class MoleFallbackBehavior to MoleBehaviors 
</li><li>
rename class StubFallbackBehavior to BehavedBehavors</li></ul></li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=ec9069cd-89d0-4958-9894-e792aeda0abc" />
      </body>
      <title>Pex 0.21.50115.2: Bugs fixes and Stubs renamed to Moles</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,ec9069cd-89d0-4958-9894-e792aeda0abc.aspx</guid>
      <link>http://blog.dotnetwiki.org/2010/01/16/Pex021501152BugsFixesAndStubsRenamedToMoles.aspx</link>
      <pubDate>Sat, 16 Jan 2010 04:14:07 GMT</pubDate>
      <description>&lt;p&gt;
We just &lt;a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx"&gt;released
Pex 0.21.50115.2&lt;/a&gt;. This release brings bug fixes, a big renaming from “Stubs” to
“Moles” and improved infrastructure to build behaved types (formerly known as beavers).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Bug Fixes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The Moles VsHost fails to execute unit tests in different assemblies. 
&lt;li&gt;
&lt;a href="http://research.microsoft.com/pex/"&gt;Pex&lt;/a&gt; deletes the report folder it
is currently writing to. 
&lt;li&gt;
Support for named indexers in Stubs 
&lt;li&gt;
Fixed bugs in how Pex reasons about System.Convert.ToBase64, DateTime 
&lt;li&gt;
Invalid support for protected members in the stubs generation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Breaking changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Stubs framework was renamed to Moles framework.&lt;/strong&gt; We have decided
to make the Moles the center of the framework and as a consequence, renamed ‘Stubs’
to ‘Moles’. (This does not mean that we encourage writing untestable code, as Mole
help to make it testable. You should still refactor your code to make it testable
whenever possible, and only use Moles when that’s the only choice). The impact is
that 
&lt;ul&gt;
&lt;li&gt;
Microsoft.Stubs.Framework was renamed to Microsoft.Moles.Framework 
&lt;li&gt;
The moles and stubs get generated in subnamespaces ‘.Moles’ rather ‘.Stubs’. 
&lt;li&gt;
See below for the list of steps to upgrade your applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
&lt;strong&gt;BaseMembers in Moles have been deprecated&lt;/strong&gt;: this helper is not useful
as it can be acheive in a better way through a constructor. We decided to remove it
to reduce code size. The second reason is that BaseMembers would only work for types
inside of the same assembly, which might seem inconsistent. 
&lt;li&gt;
&lt;strong&gt;PexGoal.Reached is replaced by PexAssert.ReachEventually().&lt;/strong&gt; The PexGoal
class has been integrated into PexAssert through the ReachEventually method which
should be used with the [PexAssertReachEventually] attribute. 
&lt;li&gt;
&lt;strong&gt;PexChoose simplified&lt;/strong&gt;: we’ve simplified the PexChoose API; you can
now get auxiliary test inputs with a single method call: PexChoose.Value&amp;lt;T&amp;gt;(“foo”).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Migrating from previous version of Pex&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Since we’ve renamed Stubs to Moles, any existing .stubx files will not work anymore.
&lt;/p&gt;
&lt;p&gt;
Take a deep breath, and apply the following steps to adapt your projects:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
change the project reference from Microsoft.Stubs.Framework.dll to Microsoft.Moles.Framework.dll 
&lt;li&gt;
rename all .stubx files to .moles, and 
&lt;ul&gt;
&lt;li&gt;
rename the top &lt;strong&gt;&amp;lt;Stubs&lt;/strong&gt; xml element to &lt;strong&gt;&amp;lt;Moles&lt;/strong&gt;. 
&lt;li&gt;
Change the XSD namespace to &lt;a href="http://schemas.microsoft.com/moles/2010/"&gt;http://schemas.microsoft.com/moles/2010/&lt;/a&gt; 
&lt;li&gt;
Right click on the .moles file in the Solution Explorer and change the Custom Tool
Name to ‘MolesGenerator’. 
&lt;li&gt;
Delete all the nested files under the .moles files&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Remove references to any compiled .Stubs.dll files in your project 
&lt;li&gt;
In general, remove all .Stubs.dll, .Stubs.xml files from your projects. 
&lt;li&gt;
Rename .Stubs namespace suffixes to .Moles. 
&lt;li&gt;
replace all [HostType(“Pex”)] attribute with [HostType(“Moles”)] 
&lt;li&gt;
in PexAssemblyInfo.cs, 
&lt;ul&gt;
&lt;li&gt;
rename using Microsoft.Pex.Framework.Stubs to Microsoft.Pex.Framework.Moles 
&lt;li&gt;
rename [assembly: PexChooseAsStubFallbackBehavior] to [assembly: PexChooseAsBehavedCurrentBehavior] 
&lt;li&gt;
rename [assembly: PexChooseAsStubFallbackBehavior] to [assembly: PexChooseAsMoleCurrentBehavior]&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
In general, the ‘Fallback’ prefix has been dropped in the following methods: 
&lt;ul&gt;
&lt;li&gt;
rename FallbackAsNotImplemented() to BehaveAsNotImplemented() 
&lt;li&gt;
rename class MoleFallbackBehavior to MoleBehaviors 
&lt;li&gt;
rename class StubFallbackBehavior to BehavedBehavors&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=ec9069cd-89d0-4958-9894-e792aeda0abc" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,ec9069cd-89d0-4958-9894-e792aeda0abc.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=94481ce9-f451-4d56-a4cc-c63f5625f41a</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,94481ce9-f451-4d56-a4cc-c63f5625f41a.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,94481ce9-f451-4d56-a4cc-c63f5625f41a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=94481ce9-f451-4d56-a4cc-c63f5625f41a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just released the version 0.20 of Pex. This version brings <b>a Beavers, an extension
of Stubs to write models, a global event view in Visual Studio and many bug fixes</b>.
Beavers are a small programatic models that build upon Moles…
</p>
        <ul>
          <li>
            <b>Beavers:</b> With <b>stubs</b> and <b>moles</b>, we provided a framework to write
record/replay tests (i.e. mock-based tests) against any .NET type, interface or not.
Beavers take you to the next level and allow you to write simple implementations <b>with
behavior</b> (hence the ‘B’eaver) that can be used to replace the external system
during testing. The benefit of using Beavers is that the resulting test cases are <b>much
more robust to code changes</b> since the tests specify the state of the system, rather
than a sequence of method calls and outcomes. We will talk a lot about Beavers in
the future. Let’s take a look at an example. The following snippet uses Moles to redirect
the constructor of a Bank class, then sets up the GetAccountById(int) method to return
an instance of IAccount, etc… This is a typical test that is based record and replay.
The problem with this technique is that it is really fragile with respect to code
changes: if the code calls different methods, the test will break.<br /><a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image3.png"><b><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image002_c6acd89e-93c0-4346-9b7a-00ef70db0ff5.gif" width="439" height="238" /></b></a><br />
The same behavior can be specified using Beavers. Beaver are simple implementations
that simulate that capture enough behavior of the original code for testing. Using
Beavers, one can specify the state of the system. The functional behavior is re-factored
away in a Beaver class and reused in all tests!<br /><a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image7.png"><b><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image004_609fde1b-a04e-43dd-888b-1e9d40da1922.gif" width="422" height="141" /></b></a><b></b></li>
          <li>
            <b>Global Event View:</b> when executing multiple explorations, it was cumbersome
to go through each exploration to investigate the events (instrumentation, object
creation, etc…). We have added a view in the Pex Explorer tree view that centralizes
the events for the entire run.<br /><a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image11.png"><b><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image006_d5b8c22e-5937-43c9-9a8d-9c6e9a3c6fb1.gif" width="507" height="354" /></b></a><b></b></li>
          <li>
            <b>Beavers for SharePoint:</b> The samples that come with Pex contains a number of
Beavers for the SharePoint object model (SPList, SPListItem, SPField, etc…) that should
help you get started with testing SharePoint with Beavers. As an example, you can
compare a mole-based test (left) and a beaver-based test (right) for a simple SharePoint
service:<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_thumb.png" width="304" height="299" /></a><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_thumb_1.png" width="244" height="128" /></a></li>
          <li>
            <b>Bug fixes and Improvements:</b>
            <ul>
              <li>
The HostType crashes non-deterministically. 
</li>
              <li>
Visual Studio 2010 crashes when loading with a ‘DocumentSite already has a site’ error
message. 
</li>
              <li>
The Stubs code generator uses a lot of memory and may crash Visual Studio. The Stubs
generator now runs out of process and does not take down Visual Studio when it runs
out of memory. 
</li>
              <li>
The Stubs code generator detects version changes of the Stubs framework to regenerate
the stubs assemblies. 
</li>
              <li>
The Pex execution produces less warnings. We’ve reviewed our warnings and moved some,
who did not matter, as messages. 
</li>
              <li>
When a Contract.Requires is failed multiple time in a stacktrace, do not allow it. 
</li>
              <li>
The object factory guesser has partial support for internal types and internal visible
to (signed assemblies not supported). 
</li>
              <li>
The ‘add’ and ‘remove’ of events can be moled to deal with events. 
</li>
              <li>
Digger does not work in Visual Studio 2010 when no test project exists.</li>
            </ul>
          </li>
          <li>
            <b>Breaking Changes: </b>The Beavers introduced a number of refactoring that might
impact users of Stubs and Moles. The .stubx file should regenerate themselves automatically,
otherwise right click on the file and select ‘Run Custom Tool’. 
<ul><li>
Most types of the Stubs framework have been moved to sub namespaces. 
</li><li>
IStubBehavior was renamed to IBehavior 
</li><li>
StubFallbackBehavior was renamed to BehaviorFallbackBehavior 
</li><li>
PexChooseAsStubFallbackBehaviorAttribute was renamed to PexChooseAsBehavedFallbackBehaviorAttribute 
</li><li>
PexChooseStubBehavior was renamed to PexChooseBehavedBehavior 
</li><li>
PexExpectedGoalsAttribute and PexGoal.Reached(…) were renamed and refactored into
PexAssertReachEventuallyAttribute and PexAssert.ReachEventually(…);</li></ul></li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=94481ce9-f451-4d56-a4cc-c63f5625f41a" />
      </body>
      <title>Pex 0.20.v0.20.41218.2: Beavers, new Event View and bugs fixes</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,94481ce9-f451-4d56-a4cc-c63f5625f41a.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/12/19/Pex020v020412182BeaversNewEventViewAndBugsFixes.aspx</link>
      <pubDate>Sat, 19 Dec 2009 02:14:57 GMT</pubDate>
      <description>&lt;p&gt;
We just released the version 0.20 of Pex. This version brings &lt;b&gt;a Beavers, an extension
of Stubs to write models, a global event view in Visual Studio and many bug fixes&lt;/b&gt;.
Beavers are a small programatic models that build upon Moles…
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;b&gt;Beavers:&lt;/b&gt; With &lt;b&gt;stubs&lt;/b&gt; and &lt;b&gt;moles&lt;/b&gt;, we provided a framework to write
record/replay tests (i.e. mock-based tests) against any .NET type, interface or not.
Beavers take you to the next level and allow you to write simple implementations &lt;b&gt;with
behavior&lt;/b&gt; (hence the ‘B’eaver) that can be used to replace the external system
during testing. The benefit of using Beavers is that the resulting test cases are &lt;b&gt;much
more robust to code changes&lt;/b&gt; since the tests specify the state of the system, rather
than a sequence of method calls and outcomes. We will talk a lot about Beavers in
the future. Let’s take a look at an example. The following snippet uses Moles to redirect
the constructor of a Bank class, then sets up the GetAccountById(int) method to return
an instance of IAccount, etc… This is a typical test that is based record and replay.
The problem with this technique is that it is really fragile with respect to code
changes: if the code calls different methods, the test will break.&lt;br&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image3.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image002_c6acd89e-93c0-4346-9b7a-00ef70db0ff5.gif" width="439" height="238"&gt;&lt;/b&gt;&lt;/a&gt;
&lt;br&gt;
The same behavior can be specified using Beavers. Beaver are simple implementations
that simulate that capture enough behavior of the original code for testing. Using
Beavers, one can specify the state of the system. The functional behavior is re-factored
away in a Beaver class and reused in all tests!&lt;br&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image7.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image004_609fde1b-a04e-43dd-888b-1e9d40da1922.gif" width="422" height="141"&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt; 
&lt;li&gt;
&lt;b&gt;Global Event View:&lt;/b&gt; when executing multiple explorations, it was cumbersome
to go through each exploration to investigate the events (instrumentation, object
creation, etc…). We have added a view in the Pex Explorer tree view that centralizes
the events for the entire run.&lt;br&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfilesBE792EA\image11.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/clip_image006_d5b8c22e-5937-43c9-9a8d-9c6e9a3c6fb1.gif" width="507" height="354"&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt; 
&lt;li&gt;
&lt;b&gt;Beavers for SharePoint:&lt;/b&gt; The samples that come with Pex contains a number of
Beavers for the SharePoint object model (SPList, SPListItem, SPField, etc…) that should
help you get started with testing SharePoint with Beavers. As an example, you can
compare a mole-based test (left) and a beaver-based test (right) for a simple SharePoint
service:&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_thumb.png" width="304" height="299"&gt;&lt;/a&gt; &lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.20.2BeaversnewEventViewandbugsfixes_C162/image_thumb_1.png" width="244" height="128"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;b&gt;Bug fixes and Improvements:&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;
The HostType crashes non-deterministically. 
&lt;li&gt;
Visual Studio 2010 crashes when loading with a ‘DocumentSite already has a site’ error
message. 
&lt;li&gt;
The Stubs code generator uses a lot of memory and may crash Visual Studio. The Stubs
generator now runs out of process and does not take down Visual Studio when it runs
out of memory. 
&lt;li&gt;
The Stubs code generator detects version changes of the Stubs framework to regenerate
the stubs assemblies. 
&lt;li&gt;
The Pex execution produces less warnings. We’ve reviewed our warnings and moved some,
who did not matter, as messages. 
&lt;li&gt;
When a Contract.Requires is failed multiple time in a stacktrace, do not allow it. 
&lt;li&gt;
The object factory guesser has partial support for internal types and internal visible
to (signed assemblies not supported). 
&lt;li&gt;
The ‘add’ and ‘remove’ of events can be moled to deal with events. 
&lt;li&gt;
Digger does not work in Visual Studio 2010 when no test project exists.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
&lt;b&gt;Breaking Changes: &lt;/b&gt;The Beavers introduced a number of refactoring that might
impact users of Stubs and Moles. The .stubx file should regenerate themselves automatically,
otherwise right click on the file and select ‘Run Custom Tool’. 
&lt;ul&gt;
&lt;li&gt;
Most types of the Stubs framework have been moved to sub namespaces. 
&lt;li&gt;
IStubBehavior was renamed to IBehavior 
&lt;li&gt;
StubFallbackBehavior was renamed to BehaviorFallbackBehavior 
&lt;li&gt;
PexChooseAsStubFallbackBehaviorAttribute was renamed to PexChooseAsBehavedFallbackBehaviorAttribute 
&lt;li&gt;
PexChooseStubBehavior was renamed to PexChooseBehavedBehavior 
&lt;li&gt;
PexExpectedGoalsAttribute and PexGoal.Reached(…) were renamed and refactored into
PexAssertReachEventuallyAttribute and PexAssert.ReachEventually(…);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=94481ce9-f451-4d56-a4cc-c63f5625f41a" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,94481ce9-f451-4d56-a4cc-c63f5625f41a.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=1daea68b-c2ac-432d-a374-b74834464b77</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,1daea68b-c2ac-432d-a374-b74834464b77.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,1daea68b-c2ac-432d-a374-b74834464b77.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=1daea68b-c2ac-432d-a374-b74834464b77</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
J’aurai le plaisir de presenter ‘<a href="http://www.dotnethub.be/agenda/stubs-moles-et-pex-test-unitaires-isole-et-parametrise">Stubs,
Moles and Pex</a>’ au premier rendez-vous de <a href="ttp://www.dotnethub.be">DotNetHub</a> 20
janvier 2010 a LLN. DotNetHub est <a href="http://www.dotnethub.be/">une communaute
.NET francophone recemment cree</a>. Au programme, beaucoup de demo a propos de Pex,
Stubs et Moles, et aussi d’un nouvel animal – les Beavers.
</p>
        <p>
Ce sera ma premiere presentation <strong>100% en francais</strong>, ce qui en soit
est un challenge assez interressant!
</p>
        <p>
ps: Pas d’accent sur les claviers qwerty, ce qui rend l’ecriture du francais beaucoup
plus facile :)
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1daea68b-c2ac-432d-a374-b74834464b77" />
      </body>
      <title>Stubs, Moles et Pex a Louvain-la-Neuve, le 20 janvier 2010.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,1daea68b-c2ac-432d-a374-b74834464b77.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/12/14/StubsMolesEtPexALouvainlaNeuveLe20Janvier2010.aspx</link>
      <pubDate>Mon, 14 Dec 2009 04:39:18 GMT</pubDate>
      <description>&lt;p&gt;
J’aurai le plaisir de presenter ‘&lt;a href="http://www.dotnethub.be/agenda/stubs-moles-et-pex-test-unitaires-isole-et-parametrise"&gt;Stubs,
Moles and Pex&lt;/a&gt;’ au premier rendez-vous de &lt;a href="ttp://www.dotnethub.be"&gt;DotNetHub&lt;/a&gt; 20
janvier 2010 a LLN. DotNetHub est &lt;a href="http://www.dotnethub.be/"&gt;une communaute
.NET francophone recemment cree&lt;/a&gt;. Au programme, beaucoup de demo a propos de Pex,
Stubs et Moles, et aussi d’un nouvel animal – les Beavers.
&lt;/p&gt;
&lt;p&gt;
Ce sera ma premiere presentation &lt;strong&gt;100% en francais&lt;/strong&gt;, ce qui en soit
est un challenge assez interressant!
&lt;/p&gt;
&lt;p&gt;
ps: Pas d’accent sur les claviers qwerty, ce qui rend l’ecriture du francais beaucoup
plus facile :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1daea68b-c2ac-432d-a374-b74834464b77" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,1daea68b-c2ac-432d-a374-b74834464b77.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=aeadd5f9-1731-4bda-9e4d-699a3a181cfa</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,aeadd5f9-1731-4bda-9e4d-699a3a181cfa.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,aeadd5f9-1731-4bda-9e4d-699a3a181cfa.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=aeadd5f9-1731-4bda-9e4d-699a3a181cfa</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just released the Pex 0.19.41110.1 just in time for TechEd session. This version
brings an <strong>updated</strong><strong>support for Visual Studio 2010 Beta2 and
.NET 4.0 and many improvements to the Moles</strong>.
</p>
        <ul>
          <li>
            <strong>Better Dev10 Beta 2 support! </strong>We’ve upgraded our support for Visual
Studio 2010 Beta 2. This includes full support for .NET 4.0 Beta 2, the Visual Studio
Unit Test HostType and the Visual Studio integration. 
<br />
Known Beta 2 issues: 1) When running Pex for the first time, the path to Visual Studio
Unit Test is not found. You need to specify the Visual Studio ‘PublicAssemblies’ path
(“c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies”), 2)
Don’t run Pex on v2 projects, Pex will crash. 
</li>
          <li>
            <strong>Smooth generation of Stubs and Moles</strong>: when you create a stubs and
moles assembly that is not a project reference, like one of the system assemblies,
the stubs and moles code generator will automatically compile it into an assembly
and add it to the project. This dramatically increases the performance of projects
using Stubs and Moles.<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_2.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb.png" width="250" height="279" /></a></li>
          <li>
            <strong>Stubs and Moles for VisualBasic.NET: </strong>the Stubs and Moles may be used
in VisualBasic.NET projects. In that case, they are embedded as a compiled assembly. 
</li>
          <li>
            <strong>Moles support for <a href="http://nunit.org" target="_blank">NUnit</a>, <a href="http://xunit.codeplex.com/" target="_blank">xUnit.Net</a> and
others:</strong> Unit tests involving Moles require the Pex profiler to work. We’ve
added a new mode to our command line runner that allows to execute your favorite unit
test framework runner under Pex. For example, the command “pex /runner=xunit.console.exe
tests.dll” will launch the xunit runner for test.dll under Pex. x64 assemblies are
still not supported.<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_1.png" width="565" height="221" /></a></li>
          <li>
            <strong>Nicer Moles Syntax:</strong> we’ve added some little tweaks to the Moles API,
such as an implicit conversion operator to the moled type, that simplifies the syntax.
Here is a small example that showcases the current syntax: step 1 moles the Bank constructor,
step 2 moles the GetAccount method and returns a mole of Account, step 3 moles the
getter and setter of the Balance property.<br />
 <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_5.png" width="436" height="490" /></a></li>
          <li>
            <strong>Fluent Mole Binding: </strong>The Bind method returns the mole itself which
allows it to be used in a fluent fashion. Interface binding is specially useful when
you need to mole custom collections – just attach an array! For example, we attach
an array of integers to a the MyList type that implements IEnumerable&lt;int&gt;.<br />
 <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_4.png" width="415" height="164" /></a></li>
          <li>
            <strong>Breaking Changes in Stubs and Moles:</strong>
            <ul>
              <li>
The stubs and moles code generator tool is now ‘StubsGenerator’. You need to path
this value in the property pages of your .stubx pages. 
</li>
              <li>
No more AsStub and AsMole: the AsStub and AsMole helpers were confusing and pretty
useless so we decided to reduce the amount of generated code by removing them. 
</li>
              <li>
The naming convention for Stubs delegate fields always mangles the parameter types
of the stubbed method, i.e. Foo(int) yields to a field called FooInt32. We used to
be smart about adding parameters but we decided to make the scheme stable and symmetric
with respect to the Moles. 
</li>
              <li>
The ‘FallbackBehavior’ property has been renamed to ‘InstanceFallbackBehavior’ in
both Stubs and Moles to make it more explicit.</li>
            </ul>
          </li>
        </ul>
        <p>
As usual, we’ve also fixed a number of bugs and added features that were reported
through our <a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank"><strong>MSDN
forums</strong></a>.
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=aeadd5f9-1731-4bda-9e4d-699a3a181cfa" />
      </body>
      <title>Pex 0.19.41110.1: Better Visual Studio 2010 and .NET 4.0 Beta 2 Support, Smoother Moles</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,aeadd5f9-1731-4bda-9e4d-699a3a181cfa.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/11/12/Pex019411101BetterVisualStudio2010AndNET40Beta2SupportSmootherMoles.aspx</link>
      <pubDate>Thu, 12 Nov 2009 19:57:20 GMT</pubDate>
      <description>&lt;p&gt;
We just released the Pex 0.19.41110.1 just in time for TechEd session. This version
brings an &lt;strong&gt;updated&lt;/strong&gt; &lt;strong&gt;support for Visual Studio 2010 Beta2 and
.NET 4.0 and many improvements to the Moles&lt;/strong&gt;.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Better Dev10 Beta 2 support! &lt;/strong&gt;We’ve upgraded our support for Visual
Studio 2010 Beta 2. This includes full support for .NET 4.0 Beta 2, the Visual Studio
Unit Test HostType and the Visual Studio integration. 
&lt;br&gt;
Known Beta 2 issues: 1) When running Pex for the first time, the path to Visual Studio
Unit Test is not found. You need to specify the Visual Studio ‘PublicAssemblies’ path
(“c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies”), 2)
Don’t run Pex on v2 projects, Pex will crash. 
&lt;li&gt;
&lt;strong&gt;Smooth generation of Stubs and Moles&lt;/strong&gt;: when you create a stubs and
moles assembly that is not a project reference, like one of the system assemblies,
the stubs and moles code generator will automatically compile it into an assembly
and add it to the project. This dramatically increases the performance of projects
using Stubs and Moles.&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb.png" width="250" height="279"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;strong&gt;Stubs and Moles for VisualBasic.NET: &lt;/strong&gt;the Stubs and Moles may be used
in VisualBasic.NET projects. In that case, they are embedded as a compiled assembly. 
&lt;li&gt;
&lt;strong&gt;Moles support for &lt;a href="http://nunit.org" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://xunit.codeplex.com/" target="_blank"&gt;xUnit.Net&lt;/a&gt; and
others:&lt;/strong&gt; Unit tests involving Moles require the Pex profiler to work. We’ve
added a new mode to our command line runner that allows to execute your favorite unit
test framework runner under Pex. For example, the command “pex /runner=xunit.console.exe
tests.dll” will launch the xunit runner for test.dll under Pex. x64 assemblies are
still not supported.&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_1.png" width="565" height="221"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;strong&gt;Nicer Moles Syntax:&lt;/strong&gt; we’ve added some little tweaks to the Moles API,
such as an implicit conversion operator to the moled type, that simplifies the syntax.
Here is a small example that showcases the current syntax: step 1 moles the Bank constructor,
step 2 moles the GetAccount method and returns a mole of Account, step 3 moles the
getter and setter of the Balance property.&lt;br&gt;
&amp;nbsp;&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_5.png" width="436" height="490"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;strong&gt;Fluent Mole Binding: &lt;/strong&gt;The Bind method returns the mole itself which
allows it to be used in a fluent fashion. Interface binding is specially useful when
you need to mole custom collections – just attach an array! For example, we attach
an array of integers to a the MyList type that implements IEnumerable&amp;lt;int&amp;gt;.&lt;br&gt;
&amp;nbsp;&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex.19VisualStudio2010Beta2SupportUnitTe_C97C/image_thumb_4.png" width="415" height="164"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;strong&gt;Breaking Changes in Stubs and Moles:&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;
The stubs and moles code generator tool is now ‘StubsGenerator’. You need to path
this value in the property pages of your .stubx pages. 
&lt;li&gt;
No more AsStub and AsMole: the AsStub and AsMole helpers were confusing and pretty
useless so we decided to reduce the amount of generated code by removing them. 
&lt;li&gt;
The naming convention for Stubs delegate fields always mangles the parameter types
of the stubbed method, i.e. Foo(int) yields to a field called FooInt32. We used to
be smart about adding parameters but we decided to make the scheme stable and symmetric
with respect to the Moles. 
&lt;li&gt;
The ‘FallbackBehavior’ property has been renamed to ‘InstanceFallbackBehavior’ in
both Stubs and Moles to make it more explicit.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As usual, we’ve also fixed a number of bugs and added features that were reported
through our &lt;a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank"&gt;&lt;strong&gt;MSDN
forums&lt;/strong&gt;&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=aeadd5f9-1731-4bda-9e4d-699a3a181cfa" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,aeadd5f9-1731-4bda-9e4d-699a3a181cfa.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=1fadab4f-ee5c-4954-b70c-8b6c317ff586</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,1fadab4f-ee5c-4954-b70c-8b6c317ff586.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,1fadab4f-ee5c-4954-b70c-8b6c317ff586.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=1fadab4f-ee5c-4954-b70c-8b6c317ff586</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ll be presenting <a href="http://www.visug.be/Eventdetails/tabid/95/EventId/18/Default.aspx">Stubs
and Moles</a> at the Visual Studio User Group on <strong>November 3rd</strong>. See
you there…
</p>
        <blockquote>
          <p>
Stubs is a lightweight framework for test stubs and detours in .NET that is entirely
based on delegates, type safe, Refactorable, debuggable and source code generated. 
<br />
Stubs also allows to replace  any .NET method with a user-defined delegate, including
non-virtual/static methods in sealed types. Stubs is fully integrated into Pex , an
automated white box test generation tool for .NET. 
<br /><a href="http://research.microsoft.com/en-us/projects/stubs/">http://research.microsoft.com/en-us/projects/stubs/</a></p>
        </blockquote>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1fadab4f-ee5c-4954-b70c-8b6c317ff586" />
      </body>
      <title>Nov 3rd: Stubs and Moles talk at VISUG</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,1fadab4f-ee5c-4954-b70c-8b6c317ff586.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/10/25/Nov3rdStubsAndMolesTalkAtVISUG.aspx</link>
      <pubDate>Sun, 25 Oct 2009 09:45:44 GMT</pubDate>
      <description>&lt;p&gt;
I’ll be presenting &lt;a href="http://www.visug.be/Eventdetails/tabid/95/EventId/18/Default.aspx"&gt;Stubs
and Moles&lt;/a&gt; at the Visual Studio User Group on &lt;strong&gt;November 3rd&lt;/strong&gt;. See
you there…
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Stubs is a lightweight framework for test stubs and detours in .NET that is entirely
based on delegates, type safe, Refactorable, debuggable and source code generated. 
&lt;br&gt;
Stubs also allows to replace&amp;nbsp; any .NET method with a user-defined delegate, including
non-virtual/static methods in sealed types. Stubs is fully integrated into Pex , an
automated white box test generation tool for .NET. 
&lt;br&gt;
&lt;a href="http://research.microsoft.com/en-us/projects/stubs/"&gt;http://research.microsoft.com/en-us/projects/stubs/&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1fadab4f-ee5c-4954-b70c-8b6c317ff586" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,1fadab4f-ee5c-4954-b70c-8b6c317ff586.aspx</comments>
      <category>Moles</category>
      <category>Pex</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=68657a76-a7c6-421a-8321-41d201f54778</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,68657a76-a7c6-421a-8321-41d201f54778.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,68657a76-a7c6-421a-8321-41d201f54778.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=68657a76-a7c6-421a-8321-41d201f54778</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have just release a new version of <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> (v0.17.xxx)
which brings <strong>new features for Moles and more bug fixes</strong>.
</p>
        <p>
          <strong>Per-Instance Moles</strong>
        </p>
        <p>
Instance methods may be <em>moled</em> differently per object instance. This is particularly
useful when multiple instances of same type need to behave differently in the same
test. For example, let’s consider a simple class Bar that has a ‘Run’ method to check
that the values are not the same. The important point here is that we would not be
able to deal with such cases if we could not mole the behavior on a per-instance basis.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_4.png" width="393" height="201" />
          </a>
        </p>
        <p>
In the test case of Run, we create to instance of MBar (the mole type of Bar) and
assign two different delegates to the ‘Value’ getter. Moles are active as soon as
they are attached (unlike the previous version) so we can just call the ‘Run’ method
once the moles are set up. In the code below, we are using the <a href="http://msdn.microsoft.com/en-us/library/bb384062.aspx" target="_blank">C#
Object Initializers</a> feature that allows us to set properties of a newly created
object within curly braces after the ‘new’ call.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_5.png" width="448" height="249" />
          </a>
        </p>
        <p>
As you may have noticed, we just wrote a parameterized unit test that takes arbitrary
‘left’ and ‘right’ values. We then simply execute Pex to find the relevant values
to cover the ‘Run’ method:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_6.png" width="425" height="74" />
          </a>
        </p>
        <p>
          <strong>Moles for Constructors</strong>
        </p>
        <p>
In same cases, objects created inside of other methods need to be moled to test the
actual program logic. With moles you can replace any constructor with your own delegate,
which you can use to attach a mole to the newly created instance. Let’s see this with
another simple example where a  ‘Run’ method creates and uses an instance of
a ‘Foo’ class.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_1.png" width="363" height="263" />
          </a>
        </p>
        <p>
Let’s say we would like to mole the call to the ‘Value’ property to return any other
value. To do so, we would need to attach a mole to a future instance of Foo, and then
mole the Value property getter. This is exactly what is done in the method below.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_2.png" width="293" height="231" />
          </a>
        </p>
        <p>
We then run Pex to find that 2 different values are needed to trigger all code paths.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_3.png" width="427" height="85" />
          </a> 
</p>
        <p>
          <strong>Mole interface binding</strong>
        </p>
        <p>
All the member implementations of an interface may be moled at once using the new
‘Bind’ method. This smells like duck typing with type safety as the Bind methods are
strongly typed. For example, we want to mole a collection type (Foes) to return a
custom list of Foo elements (which need to be moled too). The goal is to test the
sum method…
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb.png" width="309" height="232" />
          </a>
        </p>
        <p>
In the parameterized unit test case, we create an instance of Vector, which implements
IEnumerable&lt;int&gt;. Then, <strong>we can simply bind the ‘values’ array to the
mole </strong>to make Vector iterate over the array. The call to Bind will mole all
methods of MVector that are implemented by the ‘values’ parameters, effectively redirecting
all the enumeration requests to the ‘values’ array.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_22.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_9.png" width="586" height="216" />
          </a>
        </p>
        <p>
When Pex runs through the sample, it correctly understand the data flow of the parameters
through the moles and finds inputs that break the ‘sum &gt;= 0’ assertion:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_20.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_8.png" width="603" height="150" />
          </a>
        </p>
        <p>
          <strong>Compilation of Stubs assemblies</strong>
        </p>
        <p>
When one needs stubs or moles for a system assembly, it does not really make sense
to re-generate the stubs each time the solution is loaded. To that end, Stubs ships
with a command line tool that lets you easily compile a stubs assembly into a .dll:
</p>
        <blockquote>
          <p>
            <strong>stubs.exe mscorlib</strong>
          </p>
        </blockquote>
        <p>
Once the stubs assembly is compiled, i.e. mscorlib.Stubs.dll is created, you simply
have to add a reference to it in your test project to start using it. In future versions
of Pex, we will provide a better experience to support this scenario.
</p>
        <p>
          <strong>Bug Fixes</strong>
        </p>
        <ul>
          <li>
A number of fixes from the <a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank">issues
reported through the forums</a> and bugs reported to <a href="mailto:pexbug@microsoft.com">pexbug@microsoft.com</a> .</li>
        </ul>
        <p>
          <strong>Breaking Changes</strong>
        </p>
        <ul>
          <li>
The code generation of Moles was significantly changed. This might mean that you will
have to recompile your solution, and adapt all existing uses of Moles.</li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=68657a76-a7c6-421a-8321-41d201f54778" />
      </body>
      <title>Pex v0.17.41006.7 : More Moles and Bug Fixes</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,68657a76-a7c6-421a-8321-41d201f54778.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/10/07/PexV017410067MoreMolesAndBugFixes.aspx</link>
      <pubDate>Wed, 07 Oct 2009 22:02:46 GMT</pubDate>
      <description>&lt;p&gt;
We have just release a new version of &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; (v0.17.xxx)
which brings &lt;strong&gt;new features for Moles and more bug fixes&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Per-Instance Moles&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Instance methods may be &lt;em&gt;moled&lt;/em&gt; differently per object instance. This is particularly
useful when multiple instances of same type need to behave differently in the same
test. For example, let’s consider a simple class Bar that has a ‘Run’ method to check
that the values are not the same. The important point here is that we would not be
able to deal with such cases if we could not mole the behavior on a per-instance basis.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_4.png" width="393" height="201"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the test case of Run, we create to instance of MBar (the mole type of Bar) and
assign two different delegates to the ‘Value’ getter. Moles are active as soon as
they are attached (unlike the previous version) so we can just call the ‘Run’ method
once the moles are set up. In the code below, we are using the &lt;a href="http://msdn.microsoft.com/en-us/library/bb384062.aspx" target="_blank"&gt;C#
Object Initializers&lt;/a&gt; feature that allows us to set properties of a newly created
object within curly braces after the ‘new’ call.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_5.png" width="448" height="249"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
As you may have noticed, we just wrote a parameterized unit test that takes arbitrary
‘left’ and ‘right’ values. We then simply execute Pex to find the relevant values
to cover the ‘Run’ method:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_6.png" width="425" height="74"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Moles for Constructors&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In same cases, objects created inside of other methods need to be moled to test the
actual program logic. With moles you can replace any constructor with your own delegate,
which you can use to attach a mole to the newly created instance. Let’s see this with
another simple example where a&amp;nbsp; ‘Run’ method creates and uses an instance of
a ‘Foo’ class.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_1.png" width="363" height="263"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Let’s say we would like to mole the call to the ‘Value’ property to return any other
value. To do so, we would need to attach a mole to a future instance of Foo, and then
mole the Value property getter. This is exactly what is done in the method below.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_2.png" width="293" height="231"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
We then run Pex to find that 2 different values are needed to trigger all code paths.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_3.png" width="427" height="85"&gt;&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Mole interface binding&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
All the member implementations of an interface may be moled at once using the new
‘Bind’ method. This smells like duck typing with type safety as the Bind methods are
strongly typed. For example, we want to mole a collection type (Foes) to return a
custom list of Foo elements (which need to be moled too). The goal is to test the
sum method…
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb.png" width="309" height="232"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the parameterized unit test case, we create an instance of Vector, which implements
IEnumerable&amp;lt;int&amp;gt;. Then, &lt;strong&gt;we can simply bind the ‘values’ array to the
mole &lt;/strong&gt;to make Vector iterate over the array. The call to Bind will mole all
methods of MVector that are implemented by the ‘values’ parameters, effectively redirecting
all the enumeration requests to the ‘values’ array.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_9.png" width="586" height="216"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
When Pex runs through the sample, it correctly understand the data flow of the parameters
through the moles and finds inputs that break the ‘sum &amp;gt;= 0’ assertion:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.17MoreMolesandBugFixes_D241/image_thumb_8.png" width="603" height="150"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Compilation of Stubs assemblies&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When one needs stubs or moles for a system assembly, it does not really make sense
to re-generate the stubs each time the solution is loaded. To that end, Stubs ships
with a command line tool that lets you easily compile a stubs assembly into a .dll:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;stubs.exe mscorlib&lt;/strong&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Once the stubs assembly is compiled, i.e. mscorlib.Stubs.dll is created, you simply
have to add a reference to it in your test project to start using it. In future versions
of Pex, we will provide a better experience to support this scenario.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Bug Fixes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A number of fixes from the &lt;a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank"&gt;issues
reported through the forums&lt;/a&gt; and bugs reported to &lt;a href="mailto:pexbug@microsoft.com"&gt;pexbug@microsoft.com&lt;/a&gt; .&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Breaking Changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The code generation of Moles was significantly changed. This might mean that you will
have to recompile your solution, and adapt all existing uses of Moles.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=68657a76-a7c6-421a-8321-41d201f54778" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,68657a76-a7c6-421a-8321-41d201f54778.aspx</comments>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=ce09b012-e538-4c77-83b3-83d9f62cf259</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,ce09b012-e538-4c77-83b3-83d9f62cf259.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,ce09b012-e538-4c77-83b3-83d9f62cf259.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=ce09b012-e538-4c77-83b3-83d9f62cf259</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank">released</a> v0.16.40915.5
of Pex. The major highlights of this release are <strong>Moles, a lightweight detour
framework, and better support for test frameworks</strong>.
</p>
        <ul>
          <li>
            <strong>Moles, a lightweight detour framework: </strong>Moles is a new extension of
the <a href="http://research.microsoft.com/stubs" target="_blank">Stubs framework</a>:
it lets you replace any .NET method (including static methods) with your own delegate.(sample
outdated) 
<br />
Want read more about this sample? here is <a href="http://research.microsoft.com/en-us/projects/stubs/moles.aspx" target="_blank">the
full walkthrough</a>.<br />
The moles framework is not yet feature complete; moles does not support constructors
and external methods. Some types of mscorlib cannot be moled as they interact too
deeply with the CLR. 
</li>
          <li>
            <strong>Pex gets its own HostType: </strong>A HostType is a feature for the Visual
Studio Unit Test framework that lets specific unit tests be run under specialized
hosts such as Asp.Net or VisualStudio iself. In order to create reproducible test
cases using Moles, we had to implement a HostType that lets tests be run under the
Pex profiler. This is very exciting because it also opens the door for many uses of
Pex such as fault injection, dynamic checking, etc… in future versions of <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>.
When generating test cases with Pex, all the necessary annotations will be created
automatically. To turn the Pex HostType on hand-written (non-parameterized) unit tests,
simply add <strong>[HostType(“Pex”)]</strong> on your test case.<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_20.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_9.png" width="242" height="108" /></a><strong><br /></strong>This feature only works with Visual Studio Unit Test 2008. 
</li>
          <li>
            <strong>Select your test framework</strong>: the first time you invoke ‘Pex’ on your
code, Pex pops up a dialog to select your test framework of choice. You can select
which test framework should be used by default and, more importantly, where it can
be found on disk. 
<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_1.png" width="604" height="248" /></a><br />
If you do not use any test framework, Pex ships with what we call the <strong>“Direct
test framework”</strong>: in this “framework”, all methods are considered as unit
tests without any annotation or dependencies.<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_2.png" width="566" height="198" /></a><br />
These settings are stored in the registry and Pex should not bug you again. If you
want to clear these settings, go to ‘Tools –&gt; Options –&gt; Pex –&gt; General’ and clear
the TestFramework and TestFrameworkDirectory fields:<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_7.png" width="604" height="356" /></a><br /></li>
          <li>
            <strong>Thumbs up and down</strong>: We’ve added thumbs up and down buttons in the
Pex result view. <strong>We are always looking for feedback on Pex</strong>, so don’t
hesitate to click them when Pex deserves a thumbs up or a thumbs down.<br /><a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_18.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_8.png" width="604" height="76" /></a></li>
          <li>
            <strong>Performance</strong>: Many other performance improvements under the hood which
should avoid Pex hog too much memory in long running scenarios. 
</li>
          <li>
            <strong>Miscellanous improvements and bug fixes</strong>: 
<ul><li><strong>Support for String.GetHashCode():</strong> we now faithfully encode the hashing
function of strings, which means Pex can deal with dictionaries where the key is a
string. 
</li><li>
Fewer “Object Creation” messages that are not actually relevant. 
</li><li>
In VS 2010, the package used to trigger an exception when the solution loaded. This
issue is now fixed. 
</li><li>
In Visual Studio when an assembly had to be resolved manually (i.e. that little dialog
asking you where an assembly is), Pex remembers that choice and does not bug you anymore. 
</li><li>
And many other bugs that <a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank">were
reported through the forums</a>.</li></ul></li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=ce09b012-e538-4c77-83b3-83d9f62cf259" />
      </body>
      <title>Pex 0.16.40915.5: Moles, a lightweight Detour Framework, and better support for Test Frameworks</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,ce09b012-e538-4c77-83b3-83d9f62cf259.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/09/16/Pex016409155MolesALightweightDetourFrameworkAndBetterSupportForTestFrameworks.aspx</link>
      <pubDate>Wed, 16 Sep 2009 21:16:33 GMT</pubDate>
      <description>&lt;p&gt;
We just &lt;a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank"&gt;released&lt;/a&gt; v0.16.40915.5
of Pex. The major highlights of this release are &lt;strong&gt;Moles, a lightweight detour
framework, and better support for test frameworks&lt;/strong&gt;.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Moles, a lightweight detour framework: &lt;/strong&gt;Moles is a new extension of
the &lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs framework&lt;/a&gt;:
it lets you replace any .NET method (including static methods) with your own delegate.(sample
outdated) 
&lt;br&gt;
Want read more about this sample? here is &lt;a href="http://research.microsoft.com/en-us/projects/stubs/moles.aspx" target="_blank"&gt;the
full walkthrough&lt;/a&gt;.&lt;br&gt;
The moles framework is not yet feature complete; moles does not support constructors
and external methods. Some types of mscorlib cannot be moled as they interact too
deeply with the CLR. 
&lt;li&gt;
&lt;strong&gt;Pex gets its own HostType: &lt;/strong&gt;A HostType is a feature for the Visual
Studio Unit Test framework that lets specific unit tests be run under specialized
hosts such as Asp.Net or VisualStudio iself. In order to create reproducible test
cases using Moles, we had to implement a HostType that lets tests be run under the
Pex profiler. This is very exciting because it also opens the door for many uses of
Pex such as fault injection, dynamic checking, etc… in future versions of &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;.
When generating test cases with Pex, all the necessary annotations will be created
automatically. To turn the Pex HostType on hand-written (non-parameterized) unit tests,
simply add &lt;strong&gt;[HostType(“Pex”)]&lt;/strong&gt; on your test case.&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_9.png" width="242" height="108"&gt;&lt;/a&gt;&lt;strong&gt; 
&lt;br&gt;
&lt;/strong&gt;This feature only works with Visual Studio Unit Test 2008. 
&lt;li&gt;
&lt;strong&gt;Select your test framework&lt;/strong&gt;: the first time you invoke ‘Pex’ on your
code, Pex pops up a dialog to select your test framework of choice. You can select
which test framework should be used by default and, more importantly, where it can
be found on disk. 
&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_1.png" width="604" height="248"&gt;&lt;/a&gt; 
&lt;br&gt;
If you do not use any test framework, Pex ships with what we call the &lt;strong&gt;“Direct
test framework”&lt;/strong&gt;: in this “framework”, all methods are considered as unit
tests without any annotation or dependencies.&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_2.png" width="566" height="198"&gt;&lt;/a&gt; 
&lt;br&gt;
These settings are stored in the registry and Pex should not bug you again. If you
want to clear these settings, go to ‘Tools –&gt; Options –&gt; Pex –&gt; General’ and clear
the TestFramework and TestFrameworkDirectory fields:&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_7.png" width="604" height="356"&gt;&lt;/a&gt; 
&lt;br&gt;
&lt;li&gt;
&lt;strong&gt;Thumbs up and down&lt;/strong&gt;: We’ve added thumbs up and down buttons in the
Pex result view. &lt;strong&gt;We are always looking for feedback on Pex&lt;/strong&gt;, so don’t
hesitate to click them when Pex deserves a thumbs up or a thumbs down.&lt;br&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.16_733B/image_thumb_8.png" width="604" height="76"&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Many other performance improvements under the hood which
should avoid Pex hog too much memory in long running scenarios. 
&lt;li&gt;
&lt;strong&gt;Miscellanous improvements and bug fixes&lt;/strong&gt;: 
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Support for String.GetHashCode():&lt;/strong&gt; we now faithfully encode the hashing
function of strings, which means Pex can deal with dictionaries where the key is a
string. 
&lt;li&gt;
Fewer “Object Creation” messages that are not actually relevant. 
&lt;li&gt;
In VS 2010, the package used to trigger an exception when the solution loaded. This
issue is now fixed. 
&lt;li&gt;
In Visual Studio when an assembly had to be resolved manually (i.e. that little dialog
asking you where an assembly is), Pex remembers that choice and does not bug you anymore. 
&lt;li&gt;
And many other bugs that &lt;a href="http://social.msdn.microsoft.com/Forums/en/pex/threads" target="_blank"&gt;were
reported through the forums&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=ce09b012-e538-4c77-83b3-83d9f62cf259" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,ce09b012-e538-4c77-83b3-83d9f62cf259.aspx</comments>
      <category>Code Contracts</category>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=bbda23d8-9f56-4ce8-96b1-b222841d2093</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=bbda23d8-9f56-4ce8-96b1-b222841d2093</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a cool new feature that builds on <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>, <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> 
and Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a> 
(in fact, it is really just a consequence of the interaction of the 3 technologies):
stubs that act as parameterized models while complying to the interface contracts.
</p>
        <ul>
          <li>
Code Contracts provide contracts for interfaces. All implementations of that particular
interface will be instrumented with the runtime checks by the rewriter <b>at compile
time</b>. 
</li>
          <li>
Stubs is really just a code generator that provides a minimal implementation of interfaces
and relies on the C# compiler to build the code. Therefore, if a stub implements an
interface with contracts, it will automatically be instrumented by the runtime rewriter
as well. 
</li>
          <li>
Pex choices (i.e. dynamic parameter generation) may be used as the fallback behavior
of stubs. In other words, whenever a stubbed method without user-defined behavior
is called, Pex gets to pick the return value. Since the stub implementation itself
may have been instrumented with contracts, we’ve added special handling code so that <b>post-condition
violation coming from a stub are considered as an assumption</b>. This effectively
forces Pex to generate values that comply with the interface contracts. 
</li>
        </ul>
        <p>
Let’s see how this works with an example. The IFoo interface contains a single ‘GetName’
method. This method has one precondition, i should be positive and one postcondition,
the result is non null. Since interfaces cannot have a method body, we use a ‘buddy’
class to express those contracts and bind both classes using the [ContractClass] and
[ContractClassFor] attributes:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b15%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image002_92a5f4fd-8fb6-46ca-9bc9-1f3638fa9af8.gif" width="557" height="291" />
          </a>
        </p>
        <p>
We then turn on runtime rewriting for both the project under test and the test project
(Project properties –&gt; Code Contracts –&gt; Runtime checks). As a result, the stub
of IFoo automatically gets instrumented with the contracts. We can clearly see that
from the generated code of GetName in Reflector below:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b19%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image004_e18deaf5-0c62-467a-9d37-14ad9817b8b6.gif" width="572" height="278" />
          </a>
        </p>
        <p>
The last step is to write a test for IFoo. In this case, we write a parameterized
unit test that takes an IFoo instance and an integer, then simply call GetName.
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b30%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image006_2e49dd05-8b33-49fa-a84d-e1c2e2a1af1a.gif" width="337" height="150" />
          </a>
        </p>
        <p>
Since the contracts of IFoo.GetName specifies that the result should not be null,
we should not see any assertion violation in this test. Moreover, we should see a
test for the precondition considered as an expected exception:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b29%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image008_5f0984a3-2fca-4b3f-a226-3e724802109d.gif" width="622" height="82" />
          </a>
        </p>
        <p>
Note that all those behaviors rely on extensions to Pex that the wizard automatically
inserted in the PexAssemblyInfo.cs file:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b34%5d.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image010_4b1ce042-a76c-490a-a4a3-90613d0f528d.gif" width="518" height="115" />
          </a>
        </p>
        <p>
where
</p>
        <ul>
          <li>
[PexAssumeContractEnsuresFailureAtStubSurface] filters post-condition violations in
stubs as assumptions, 
</li>
          <li>
[PexChooseAsStubFallbackBehavior] installs Pex choices as the fallback behavior of
stubs, 
</li>
          <li>
[PexStubsPackage] load the stubs package (this is a standard procedure for Pex packages), 
</li>
          <li>
[PexUseStubsFromTestAssembly] specifies to Pex that it should considers stub types
when trying to test interfaces or abstract classes. 
</li>
        </ul>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=bbda23d8-9f56-4ce8-96b1-b222841d2093" />
      </body>
      <title>Stubs as Parameterized Models with Contracts</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/05/02/StubsAsParameterizedModelsWithContracts.aspx</link>
      <pubDate>Sat, 02 May 2009 17:19:16 GMT</pubDate>
      <description>&lt;p&gt;
This is a cool new feature that builds on &lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;, &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;&amp;#160;
and Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt;&amp;#160;
(in fact, it is really just a consequence of the interaction of the 3 technologies):
stubs that act as parameterized models while complying to the interface contracts.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Code Contracts provide contracts for interfaces. All implementations of that particular
interface will be instrumented with the runtime checks by the rewriter &lt;b&gt;at compile
time&lt;/b&gt;. 
&lt;/li&gt;
&lt;li&gt;
Stubs is really just a code generator that provides a minimal implementation of interfaces
and relies on the C# compiler to build the code. Therefore, if a stub implements an
interface with contracts, it will automatically be instrumented by the runtime rewriter
as well. 
&lt;/li&gt;
&lt;li&gt;
Pex choices (i.e. dynamic parameter generation) may be used as the fallback behavior
of stubs. In other words, whenever a stubbed method without user-defined behavior
is called, Pex gets to pick the return value. Since the stub implementation itself
may have been instrumented with contracts, we’ve added special handling code so that &lt;b&gt;post-condition
violation coming from a stub are considered as an assumption&lt;/b&gt;. This effectively
forces Pex to generate values that comply with the interface contracts. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Let’s see how this works with an example. The IFoo interface contains a single ‘GetName’
method. This method has one precondition, i should be positive and one postcondition,
the result is non null. Since interfaces cannot have a method body, we use a ‘buddy’
class to express those contracts and bind both classes using the [ContractClass] and
[ContractClassFor] attributes:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b15%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image002_92a5f4fd-8fb6-46ca-9bc9-1f3638fa9af8.gif" width="557" height="291" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We then turn on runtime rewriting for both the project under test and the test project
(Project properties –&amp;gt; Code Contracts –&amp;gt; Runtime checks). As a result, the stub
of IFoo automatically gets instrumented with the contracts. We can clearly see that
from the generated code of GetName in Reflector below:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b19%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image004_e18deaf5-0c62-467a-9d37-14ad9817b8b6.gif" width="572" height="278" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The last step is to write a test for IFoo. In this case, we write a parameterized
unit test that takes an IFoo instance and an integer, then simply call GetName.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b30%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image006_2e49dd05-8b33-49fa-a84d-e1c2e2a1af1a.gif" width="337" height="150" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Since the contracts of IFoo.GetName specifies that the result should not be null,
we should not see any assertion violation in this test. Moreover, we should see a
test for the precondition considered as an expected exception:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b29%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image008_5f0984a3-2fca-4b3f-a226-3e724802109d.gif" width="622" height="82" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Note that all those behaviors rely on extensions to Pex that the wizard automatically
inserted in the PexAssemblyInfo.cs file:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles4A3CCC8\image%5b34%5d.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsasParameterizedModeldwithCodeContra_D4E6/clip_image010_4b1ce042-a76c-490a-a4a3-90613d0f528d.gif" width="518" height="115" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
where
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
[PexAssumeContractEnsuresFailureAtStubSurface] filters post-condition violations in
stubs as assumptions, 
&lt;/li&gt;
&lt;li&gt;
[PexChooseAsStubFallbackBehavior] installs Pex choices as the fallback behavior of
stubs, 
&lt;/li&gt;
&lt;li&gt;
[PexStubsPackage] load the stubs package (this is a standard procedure for Pex packages), 
&lt;/li&gt;
&lt;li&gt;
[PexUseStubsFromTestAssembly] specifies to Pex that it should considers stub types
when trying to test interfaces or abstract classes. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=bbda23d8-9f56-4ce8-96b1-b222841d2093" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,bbda23d8-9f56-4ce8-96b1-b222841d2093.aspx</comments>
      <category>Code Contracts</category>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=18226b58-0d8f-484e-a07d-12f3ebae8c1e</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=18226b58-0d8f-484e-a07d-12f3ebae8c1e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We just made a <a href="http://research.microsoft.com/pex/downloads.aspx">quick release</a> to
fix another installer issue related to missing packages. Along the way, we’ve added
an <strong>Exploration Tree View</strong> and <strong>Partial Stubs</strong> support.
</p>
        <p>
          <strong>Exploration Tree View</strong>
        </p>
        <p>
The exploration tree view displays the list of explorations to be executed, running
and finished. It serves as a progress indicator but also as a smooth result explorer.
When browsing through the tree, <a href="http://research.microsoft.com/pex" target="_blank">Pex</a> will
synchronize the exploration result view and the tree view.
</p>
        <p>
The tree view populates each namespace with the fixture types and exploration methods,
and provide a visual feedback on the progress of Pex.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_1.png" width="390" height="363" />
          </a>
        </p>
        <p>
When you browse through the exploration and generated test nodes, Pex automatically
synchronizes the exploration result display. This makes it really easy to start from
an high-level view of the failures and drill into a particular generated test, with
stack trace and parameter table.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb.png" width="604" height="212" />
          </a>
        </p>
        <p>
          <strong>
          </strong>
        </p>
        <p>
          <strong>Partial Stubs</strong>
        </p>
        <p>
Stubs lets you call the base class implementation of methods as a fallback behavior.
This functionality is commonly referred as <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks">Partial
Mocks</a> or Partial Stubs and is useful to test abstract classes in isolation. Stubs
inheriting from classes have a “CallBase” property that can turn this mode on and
off.
</p>
        <p>
Let see this with the <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks">RhinoMocks
example on partial mocks</a>. Given an abstract ProcessorBase class,
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_4.png" width="337" height="207" />
          </a>
        </p>
        <p>
we write a test for the Inc method. To do so, we provide a stub implementation of
Add that simply increment a counter.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_3.png" width="558" height="210" />
          </a>
        </p>
        <p>
          <strong>Miscellaneous</strong>
        </p>
        <ul>
          <li>
PexAssume/PexAssert.EnumIsDefine checks that a particular value is defined in an enum. 
</li>
          <li>
Missing OpenMP files in the installer break Pex.</li>
        </ul>
        <p>
          <strong>
          </strong>
        </p>
        <p>
          <strong>Poll:</strong> should we skip 0.13 and go straight for 0.14? :)
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=18226b58-0d8f-484e-a07d-12f3ebae8c1e" />
      </body>
      <title>Pex 0.12.40430.3 : Exploration Tree View, Partial Stubs…</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/05/01/Pex012404303ExplorationTreeViewPartialStubs.aspx</link>
      <pubDate>Fri, 01 May 2009 20:28:25 GMT</pubDate>
      <description>&lt;p&gt;
We just made a &lt;a href="http://research.microsoft.com/pex/downloads.aspx"&gt;quick release&lt;/a&gt; to
fix another installer issue related to missing packages. Along the way, we’ve added
an &lt;strong&gt;Exploration Tree View&lt;/strong&gt; and &lt;strong&gt;Partial Stubs&lt;/strong&gt; support.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Exploration Tree View&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The exploration tree view displays the list of explorations to be executed, running
and finished. It serves as a progress indicator but also as a smooth result explorer.
When browsing through the tree, &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt; will
synchronize the exploration result view and the tree view.
&lt;/p&gt;
&lt;p&gt;
The tree view populates each namespace with the fixture types and exploration methods,
and provide a visual feedback on the progress of Pex.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_1.png" width="390" height="363" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
When you browse through the exploration and generated test nodes, Pex automatically
synchronizes the exploration result display. This makes it really easy to start from
an high-level view of the failures and drill into a particular generated test, with
stack trace and parameter table.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb.png" width="604" height="212" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Partial Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Stubs lets you call the base class implementation of methods as a fallback behavior.
This functionality is commonly referred as &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks"&gt;Partial
Mocks&lt;/a&gt; or Partial Stubs and is useful to test abstract classes in isolation. Stubs
inheriting from classes have a “CallBase” property that can turn this mode on and
off.
&lt;/p&gt;
&lt;p&gt;
Let see this with the &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks"&gt;RhinoMocks
example on partial mocks&lt;/a&gt;. Given an abstract ProcessorBase class,
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_4.png" width="337" height="207" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
we write a test for the Inc method. To do so, we provide a stub implementation of
Add that simply increment a counter.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pex0.12.404ExplorationTreeViewPartialSt_D1CB/image_thumb_3.png" width="558" height="210" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Miscellaneous&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
PexAssume/PexAssert.EnumIsDefine checks that a particular value is defined in an enum. 
&lt;/li&gt;
&lt;li&gt;
Missing OpenMP files in the installer break Pex.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Poll:&lt;/strong&gt; should we skip 0.13 and go straight for 0.14? :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=18226b58-0d8f-484e-a07d-12f3ebae8c1e" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,18226b58-0d8f-484e-a07d-12f3ebae8c1e.aspx</comments>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>Update: Andrew Kazyrevich does the final performance analysis <a href="http://codevanced.net/post/The-Shark-Fin-Pex.aspx">on
his blog</a>. 
<br />
Update II: Stubs v0.12.40430.3 has Partial Stubs support. </em>
        </p>
        <p>
          <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a> is a lightweight
stub framework that is entirely based on delegates. We designed it so that it brings
as little overhead as possible, and as a side effect, is very effective with <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>.
In this post, we’ll see how Stubs ‘look’ with respect to other frameworks.
</p>
        <p>
          <strong>Mocking-framework-compare</strong>
        </p>
        <p>
          <a href="http://codevanced.net/" target="_blank">Andrew Kazyrevich</a> started a project, <a href="http://code.google.com/p/mocking-frameworks-compare/" target="_blank">mocking-framework-compare</a>,
back in February that compared Moq, Rhino, NMock2 and Isolator. This is project compares
various ‘mocking scenarios’ across all those frameworks. I added Stubs to the mix
today (go <a href="http://code.google.com/p/mocking-frameworks-compare/source/detail?r=56" target="_blank">check
it out</a>).
</p>
        <p>
          <strong>What’s a stub in Stubs anyway?</strong>
        </p>
        <p>
Before we dig in, let’s recap how stubs look like when you use Stubs. Stubs uses delegate
to ‘hook’ behavior to interface members.<strong></strong>For every stubbed interface
and class, code is generated at a compile time: One stub class per interface and class.
For each stubbed method, the stub class contains a field. The field has a delegate
type matching the stubbed method. As a user, you can simply attach delegates (or lambdas)
to the delegate fields to assign<strong>*any*</strong> behavior to each member. If
no user delegate is set, Stubs calls into a fallback behavior, i.e. throw or return
the default value. 
</p>
        <p>
Let’s take one of the examples of mocking-framework-compare. The little snippet below
‘stubs’ the TouchIron() method (which is implemented explicitly) by attaching a lambda
to the TouchIron field.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb.png" width="324" height="133" />
          </a>
        </p>
        <p>
SIHand is the stub type of the IHand interface, it was generated at compile time by
the Stubs framework. Its implementation looks more or less like this:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_1.png" width="504" height="289" />
          </a>
        </p>
        <p>
The TouchIron methods really shows the main idea behind stubs: delegates are all we
need to move behavior around.
</p>
        <p>
          <strong>Stubs: relying on the language rather than an API</strong>
        </p>
        <p>
One of the differences of Stubs with other mock frameworks is that Stubs does not
have any API: delegates, lambdas, closures are all features of the programming language,
while assertions are part of the test framework. This is quite obvious when we compare
the BrainTest <a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/MoqTests/BrainTests.cs" target="_blank">using
Moq</a> and <a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/StubsTests/BrainTests.cs" target="_blank">using
Stubs</a>. In this test, we need to ensure that the brain coordinates the hand and
the mouth so that when a hot iron is touched by the hand, the mouth yells.
</p>
        <ul>
          <li>
Moq: we set up the hand to throw a burn exception when touched with a hot iron and
verify that the mouth yelled. 
</li>
        </ul>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_2.png" width="612" height="172" />
          </a>
        </p>
        <p>
Moq, as Rhino or Isolate, make smart use of expression trees and/or Reflection.Emit
to define the mock behavior. The expectation and behavior are set through nice and
fluent APIs which really make the developer’s life’s easier.
</p>
        <ul>
          <li>
Stubs: same scenario, we attach a lambda that throws if iron is hot and use a local
to verify that Yell is called (this local is pushed to the heap by the compiler). 
</li>
        </ul>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_3.png" width="402" height="316" />
          </a> 
</p>
        <p>
Stubs does not have any API. It relies on lambdas (to define new behaviors), closures
(to track side effects) which are given for free by the C# 3.0 language.
</p>
        <p>
          <strong>Performance numbers</strong>
        </p>
        <p>
Does performance matter when it comes to mocking? It’s not really the question we
are trying to answer here. We’re just looking at the benchmark results from the mocking-framework-compare
project. When looking at the results, you’ll notice that Stubs may be 100x to 1000x
faster than other frameworks. This is no surprise since stubs boil down to a virtual
method call, while other frameworks do much more work (in fact we expected worse numbers).
</p>
        <blockquote>
          <p>
Data units of msec resolution = 0.394937 usec 
</p>
          <p>
Mocking methods. 
<br />
Moq      : 100 repeats:  37.471 +- 12%   msec 
<br />
Rhino    : 100 repeats:  38.030 +- 7%    msec 
<br />
NMock2   : 100 repeats:  24.035 +- 4%    msec 
<br /><strong>Stubs    : 100 repeats:   0.115 +- 8%   
msec </strong></p>
          <p>
Mocking events. 
<br />
Moq      : 100 repeats:  86.913 +- 7%   
msec 
<br />
Rhino    : 100 repeats:  61.142 +- 6%    msec 
<br />
NMock2   : 100 repeats:  27.378 +- 6%    msec 
<br /><strong>Stubs    : 100 repeats:   0.071 +- 6%   
msec </strong></p>
          <p>
Mocking properties. 
<br />
Moq      : 100 repeats:  82.434 +- 6%   
msec 
<br />
Rhino    : 100 repeats:  47.471 +- 5%    msec 
<br />
NMock2   : 100 repeats:  11.334 +- 10%   msec 
<br /><strong>Stubs    : 100 repeats:   0.042 +- 15%  
msec </strong></p>
          <p>
Mocking method arguments. 
<br />
Moq      : 100 repeats: 142.668 +- 4%    msec 
<br />
Rhino    : 100 repeats:  45.118 +- 5%    msec 
<br />
NMock2   : 100 repeats:  22.344 +- 7%    msec 
<br /><strong>Stubs    : 100 repeats:   0.078 +- 4%   
msec </strong></p>
          <p>
Partial mocks. 
<br />
Moq      : 100 repeats: 117.581 +- 5%    msec 
<br />
Rhino    : 100 repeats:  58.827 +- 6%    msec 
<br /><strong>Stubs : 100 repeats:   0.054 +- 6%    msec </strong></p>
          <p>
Recursive mocks. 
<br />
Moq      : 100 repeats:  92.482 +- 4%   
msec 
<br />
Rhino    : 100 repeats:  40.921 +- 3%    msec 
<br /><strong>Stubs    : 100 repeats:   0.493 +- 18%  
msec 
<br /></strong>Press any key to continue . . .
</p>
          <p>
          </p>
          <p>
          </p>
        </blockquote>
        <strong>
        </strong>
        <p>
          <strong>Stubs limitations</strong>
        </p>
        <p>
There are many areas where the Stubs fall short or simply don’t support it. Currently,
Stubs are only emitted for C# and <a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks" target="_blank">partial
mocks</a> will be supported in the next version.
</p>
        <p>
          <strong>Getting started with Stubs</strong>
        </p>
        <p>
Stubs comes with the <a href="http://research.microsoft.com/pex/downloads.aspx" target="_blank">Pex
installer</a>. If you’re interested on using it, check out the <a href="http://research.microsoft.com/en-us/projects/stubs/gettingstarted.aspx" target="_blank">getting
started page</a> on the Stubs project page where you can also download the full Stubs
primer.
</p>
        <p>
Cheers, Peli
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2" />
      </body>
      <title>Stubs: Comparison with other mocking frameworks</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/04/23/StubsComparisonWithOtherMockingFrameworks.aspx</link>
      <pubDate>Thu, 23 Apr 2009 04:58:03 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;Update: Andrew Kazyrevich does the final performance analysis &lt;a href="http://codevanced.net/post/The-Shark-Fin-Pex.aspx"&gt;on
his blog&lt;/a&gt;. 
&lt;br /&gt;
Update II: Stubs v0.12.40430.3 has Partial Stubs support. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt; is a lightweight
stub framework that is entirely based on delegates. We designed it so that it brings
as little overhead as possible, and as a side effect, is very effective with &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;.
In this post, we’ll see how Stubs ‘look’ with respect to other frameworks.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Mocking-framework-compare&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codevanced.net/" target="_blank"&gt;Andrew Kazyrevich&lt;/a&gt; started a project, &lt;a href="http://code.google.com/p/mocking-frameworks-compare/" target="_blank"&gt;mocking-framework-compare&lt;/a&gt;,
back in February that compared Moq, Rhino, NMock2 and Isolator. This is project compares
various ‘mocking scenarios’ across all those frameworks. I added Stubs to the mix
today (go &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/detail?r=56" target="_blank"&gt;check
it out&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;What’s a stub in Stubs anyway?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Before we dig in, let’s recap how stubs look like when you use Stubs. Stubs uses delegate
to ‘hook’ behavior to interface members.&lt;strong&gt; &lt;/strong&gt;For every stubbed interface
and class, code is generated at a compile time: One stub class per interface and class.
For each stubbed method, the stub class contains a field. The field has a delegate
type matching the stubbed method. As a user, you can simply attach delegates (or lambdas)
to the delegate fields to assign&lt;strong&gt;*any*&lt;/strong&gt; behavior to each member. If
no user delegate is set, Stubs calls into a fallback behavior, i.e. throw or return
the default value. 
&lt;/p&gt;
&lt;p&gt;
Let’s take one of the examples of mocking-framework-compare. The little snippet below
‘stubs’ the TouchIron() method (which is implemented explicitly) by attaching a lambda
to the TouchIron field.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb.png" width="324" height="133" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
SIHand is the stub type of the IHand interface, it was generated at compile time by
the Stubs framework. Its implementation looks more or less like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_1.png" width="504" height="289" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The TouchIron methods really shows the main idea behind stubs: delegates are all we
need to move behavior around.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs: relying on the language rather than an API&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
One of the differences of Stubs with other mock frameworks is that Stubs does not
have any API: delegates, lambdas, closures are all features of the programming language,
while assertions are part of the test framework. This is quite obvious when we compare
the BrainTest &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/MoqTests/BrainTests.cs" target="_blank"&gt;using
Moq&lt;/a&gt; and &lt;a href="http://code.google.com/p/mocking-frameworks-compare/source/browse/trunk/Tests/CS/StubsTests/BrainTests.cs" target="_blank"&gt;using
Stubs&lt;/a&gt;. In this test, we need to ensure that the brain coordinates the hand and
the mouth so that when a hot iron is touched by the hand, the mouth yells.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Moq: we set up the hand to throw a burn exception when touched with a hot iron and
verify that the mouth yelled. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_2.png" width="612" height="172" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Moq, as Rhino or Isolate, make smart use of expression trees and/or Reflection.Emit
to define the mock behavior. The expectation and behavior are set through nice and
fluent APIs which really make the developer’s life’s easier.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Stubs: same scenario, we attach a lambda that throws if iron is hot and use a local
to verify that Yell is called (this local is pushed to the heap by the compiler). 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/StubsComparisonwithothermockingframework_1415A/image_thumb_3.png" width="402" height="316" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Stubs does not have any API. It relies on lambdas (to define new behaviors), closures
(to track side effects) which are given for free by the C# 3.0 language.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Performance numbers&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Does performance matter when it comes to mocking? It’s not really the question we
are trying to answer here. We’re just looking at the benchmark results from the mocking-framework-compare
project. When looking at the results, you’ll notice that Stubs may be 100x to 1000x
faster than other frameworks. This is no surprise since stubs boil down to a virtual
method call, while other frameworks do much more work (in fact we expected worse numbers).
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Data units of msec resolution = 0.394937 usec 
&lt;/p&gt;
&lt;p&gt;
Mocking methods. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 37.471 +- 12%&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 38.030 +- 7%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 24.035 +- 4%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.115 +- 8%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking events. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 86.913 +- 7%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 61.142 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 27.378 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.071 +- 6%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking properties. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 82.434 +- 6%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 47.471 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 11.334 +- 10%&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.042 +- 15%&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Mocking method arguments. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats: 142.668 +- 4%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 45.118 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
NMock2&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 22.344 +- 7%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.078 +- 4%&amp;#160;&amp;#160;&amp;#160;
msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Partial mocks. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats: 117.581 +- 5%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 58.827 +- 6%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs : 100 repeats:&amp;#160;&amp;#160; 0.054 +- 6%&amp;#160;&amp;#160;&amp;#160; msec &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Recursive mocks. 
&lt;br /&gt;
Moq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 92.482 +- 4%&amp;#160;&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
Rhino&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160; 40.921 +- 3%&amp;#160;&amp;#160;&amp;#160; msec 
&lt;br /&gt;
&lt;strong&gt;Stubs&amp;#160;&amp;#160;&amp;#160; : 100 repeats:&amp;#160;&amp;#160; 0.493 +- 18%&amp;#160;&amp;#160;
msec 
&lt;br /&gt;
&lt;/strong&gt;Press any key to continue . . .
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;strong&gt;&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;Stubs limitations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
There are many areas where the Stubs fall short or simply don’t support it. Currently,
Stubs are only emitted for C# and &lt;a href="http://ayende.com/Wiki/Default.aspx?Page=Rhino+Mocks+Partial+Mocks" target="_blank"&gt;partial
mocks&lt;/a&gt; will be supported in the next version.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Getting started with Stubs&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Stubs comes with the &lt;a href="http://research.microsoft.com/pex/downloads.aspx" target="_blank"&gt;Pex
installer&lt;/a&gt;. If you’re interested on using it, check out the &lt;a href="http://research.microsoft.com/en-us/projects/stubs/gettingstarted.aspx" target="_blank"&gt;getting
started page&lt;/a&gt; on the Stubs project page where you can also download the full Stubs
primer.
&lt;/p&gt;
&lt;p&gt;
Cheers, Peli
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,7c5d5cdd-7ebc-4a3d-8fb1-e84b187343b2.aspx</comments>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=3f0e2745-a604-4772-a81d-bf7d75faa21a</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=3f0e2745-a604-4772-a81d-bf7d75faa21a</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Nikolai just announced the latest drop
of <a href="http://research.microsoft.com/pex" target="_blank">Pex</a>, 0.11.40421.0.
Get <a href="http://blogs.msdn.com/nikolait/archive/2009/04/21/pex-0-11-released-delegates-exception-trees-and-stubs.aspx" target="_blank">all
the details</a> on his blog.<img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=3f0e2745-a604-4772-a81d-bf7d75faa21a" /></body>
      <title>Pex v0.11.40421.0 : Delegates As Parameters, Exception Tree View, Better Stubs.</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/04/22/PexV011404210DelegatesAsParametersExceptionTreeViewBetterStubs.aspx</link>
      <pubDate>Wed, 22 Apr 2009 00:10:17 GMT</pubDate>
      <description>Nikolai just announced the latest drop of &lt;a href="http://research.microsoft.com/pex" target="_blank"&gt;Pex&lt;/a&gt;,
0.11.40421.0. Get &lt;a href="http://blogs.msdn.com/nikolait/archive/2009/04/21/pex-0-11-released-delegates-exception-trees-and-stubs.aspx" target="_blank"&gt;all
the details&lt;/a&gt; on his blog.&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=3f0e2745-a604-4772-a81d-bf7d75faa21a" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,3f0e2745-a604-4772-a81d-bf7d75faa21a.aspx</comments>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=83fde01f-786e-456d-b1c4-c8dd52448e69</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=83fde01f-786e-456d-b1c4-c8dd52448e69</wfw:commentRss>
      <slash:comments>12</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <blockquote>
          <p>
            <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank">
              <strong>Download
the new version!</strong>
            </a>
          </p>
        </blockquote>
        <p>
Today we’ve released a new release of <a href="http://research.microsoft.com/pex">Pex</a> on
DevLabs and on our academic downloads. This highlights of this release are: <a href="http://www.nunit.org" target="_blank">NUnit</a>, <a href="http://www.mbunit.com/" target="_blank">MbUnit</a> and <a href="http://xunit.codeplex.com/" target="_blank">xUnit.net</a> support
out of the box, <strong>writing <a href="http://research.microsoft.com/pex">parameterized
unit tests</a> in VisualBasic.NET and F#, better <a href="http://research.microsoft.com/contracts">Code
Contracts</a> support</strong>. As always, if we encourage you to send us feedback,
bugs, stories on our forums at <a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/">http://social.msdn.microsoft.com/Forums/en-US/pex/threads/</a> .
</p>
        <p>
          <strong>
            <a href="http://www.nunit.org" target="_blank">NUnit</a>, <a href="http://www.mbunit.com" target="_blank">MbUnit</a> and <a href="http://www.codeplex.com/xunit">xUnit.net</a> supported
out of the box</strong>
        </p>
        <p>
Pex now supports MSTest, NUnit, MbUnit and xUnit.net out of the box. Pex will automatically
detect which framework you are using by inspecting the assembly reference list, and
automatically save the generated tests decorated with the correct attributes for that
framework. 
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_22.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_10.png" width="604" height="351" />
          </a>
        </p>
        <p>
The default test framework can also be specified through the global options (Tools
–&gt; Options –&gt; Pex –&gt; enter the test framework name in TestFramework).
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_7.png" width="604" height="257" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <strong>Writing Parameterized Unit Tests in VisualBasic.NET</strong>
        </p>
        <p>
While the Pex white box analysis engine works at the MSIL level, Pex only emits C#
code for now. In previous releases, this limitation made it impossible to use Pex
parameterized unit tests from non-C# code. In this release, we have worked around
this problem by automatically saving the generated tests in a ‘satellite’ C# project.
</p>
        <p>
Let’s see this with an example. The screenshot below shows a single VisualBasic.NET
test project with a Pex parameterized unit test:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image3.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image002_0dd1c4a7-6732-42b8-b6fe-76f7499e6a66.gif" width="604" height="237" />
            </b>
          </a>
        </p>
        <p>
We can right-click in the HelloTest.Hello method and select “Run Pex Explorations”:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image7.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image004_31e0ecca-a518-4ec3-9ad4-3fef0bb58593.gif" width="305" height="91" />
            </b>
          </a>
        </p>
        <p>
At this point, Pex will start exploring the test in the background as usual. This
is where the new support comes in: When a generated test comes back to Visual Studio,
Pex will save it in a separate C# project automatically (after asking you where to
drop the new project):
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image19.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image006_324456a0-a756-4cfe-b9cb-e7eb8a9db8a0.gif" width="604" height="391" />
            </b>
          </a>
        </p>
        <p>
The generated tests are now ready to be run just as any other unit tests!
</p>
        <p>
          <strong>Writing Parameterized Unit Tests from F#</strong>
        </p>
        <p>
Similarly to VisualBasic.NET, we’ve made improvements in our infrastructure to enable
writing parameterized unit tests in <strong>F#</strong>. Let’s see this with a familiar
example. We have a single F# library that has xUnit.net unit tests and reference Microsoft.Pex.Framework
(project Library2 below). In that project, we add a parameterized unit test (hello_test):
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image32%5b1%5d.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image008_709d95c3-12c4-4805-b549-2982d5341032.gif" width="604" height="235" />
            </b>
          </a>
        </p>
        <p>
We can right-click on the <strong>test method name</strong> and Pex will start the
exploration of that test in the background. Because of the limitations of the F# project
system, you <strong>absolutely</strong> need to right-click on the<strong> method
name</strong> in F# if you want contextual test selection to work. Because the project
is already referencing xunit.dll, Pex will also automatically detect that you are
using xUnit.net and use that framework. When the first test case comes back to VisualStudio,
Pex saves it in a separate C# project:
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image39.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image010_69f5c0e9-4c03-4251-a79a-38c7ffbb3a19.gif" width="604" height="341" />
            </b>
          </a>
        </p>
        <p>
The tests are saved in the generated test project and ready to be run by your favorite
test runner!
</p>
        <p>
          <strong>PexObserve: Observing values, Asserting values</strong>
        </p>
        <p>
We’ve completely re-factored the way values can be logged on the table or saved as
assertions in the generated tests. The following example shows various ways to log
and assert values:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_3.png" width="451" height="228" />
          </a>
        </p>
        <p>
In the Observe method, we use the return value and out parameter output to automatically
log and assert those values. Additionally, we add “view input” on the fly to the parameter
table through the ValueForViewing method, and we add “check input” to be asserted
through the ValueAtEndOfTest method. After running Pex, we get the following results:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_4.png" width="373" height="63" />
          </a>
        </p>
        <p>
As expected, input, ‘view input’, output and result show up in the parameter table.
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_5.png" width="599" height="266" />
          </a>
        </p>
        <p>
In the generated test, we see assertions for the return value, out parameters and
other values passed through the ValueAtEndOfTest method.
</p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/contracts">Code Contracts</a> : Reproducible
generated tests</strong>
        </p>
        <p>
When Pex generates a unit test that relied on a runtime contract, Pex also adds a
check to the unit test which validates that the contracts have been injected into
the code by the contracts rewriter. If the code is not rewritten when re-executing
the unit test, it is marked as inconclusive. You will appreciate this behavior when
you run your unit tests both in Release and in Debug builds, which usually differ
in how contracts get injected.
</p>
        <p>
          <a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image43.png">
            <b>
              <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image012_32c70deb-1184-48c7-a1cd-16e1c19559d3.gif" width="604" height="177" />
            </b>
          </a>
        </p>
        <p>
          <strong>Code Contracts:  Automatic filtering of the contract violations</strong>
        </p>
        <p>
When Pex generates a test that violates a Code Contract pre-condition (i.e. Contract.Requires),
there are basically two scenarios: the precondition was on top of the stack and should
be considered as an expected exception; or it is a nested exception and should be
considered as a bug. Pex provides a default exception filtering that implements this
behavior.
</p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>: simplified
syntax</strong>
        </p>
        <p>
We’ve considerably simplified the syntax of stubs by removing the ‘this’ parameter
from the stub delegate definition. Let’s illustrate this with a test that stubs the
‘ReadAllText’ method of a fictitious ‘IFileSystem’ interface.  
</p>
        <p>
          <img src="http://research.microsoft.com/en-us/projects/stubs/stubexample.png" />
        </p>
        <p>
          <strong>
            <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a>: generic
methods</strong>
        </p>
        <p>
The <a href="http://research.microsoft.com/stubs" target="_blank">Stubs</a> framework
now supports stubbing generic methods by providing particular instantiations of that
method. In the following example, the generic Bar&lt;T&gt; method is stubbed for the
particular Bar&lt;int&gt; instantiation:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb.png" width="435" height="119" />
          </a>
        </p>
        <p>
          <strong>Stubs and Pex: Pex will choose the stubs behavior by default</strong>
        </p>
        <p>
We provide a new custom attribute, PexChooseAsStubFallbackBehaviorAttribute, that
hooks Pex choices to the Stub fallback behavior. To illustrate what this means, let’s
modify slightly the example above by removing the stub of ReadAllText:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_1.png" width="455" height="216" />
          </a>
        </p>
        <p>
If this test was to be run without the PexChooseAsStubFallbackBehavior attribute,
it would throw a StubNotImplementedException. However, with the PexChooseAsStubFallbackBehavior
attribute, the fallback behavior calls into PexChoose to ask Pex for a new string.
In this example in particular, on each call to ReadAllText, Pex will generate a new
string for the result. You can see this string as a new parameter to the parameterized
unit test. Therefore, when we run this test under Pex, we see different behavior happening,
including the “hello world” file:
</p>
        <p>
          <a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_2.png" width="584" height="90" />
          </a>
        </p>
        <p>
Note that all the necessary attributes are added at the assembly level by the Pex
Wizard.
</p>
        <p>
          <strong>Miscellanous bug fixes and improvements</strong>
        </p>
        <ul>
          <li>
[fixed] Dialogs do not render correctly under high DPI 
</li>
          <li>
When a generic parameterized unit tests does not have any generic argument instantiations,
Pex makes a guess for you. 
</li>
          <li>
When a test parameter is an interface or an abstract class, Pex now searches the known
assemblies for implementations and concrete classes. In particular, that means that
Pex will often automatically use the automatically generated Stubs implementations
for interfaces or abstract classes. 
</li>
          <li>
Static parameterized unit tests are supported (if static tests are supported by your
test framework) 
</li>
          <li>
Better solving of decimal and floating point constraints. We will report on the details
later. 
</li>
        </ul>
        <p>
          <strong>Breaking Changes</strong>
        </p>
        <ul>
          <li>
The PexFactoryClassAttribute is no longer needed and has been removed. Now, Pex will
pick up object factory methods marked with the PexFactoryMethodAttribute from any <i>static
class</i> in the test project containing the parameterized unit tests. If the generated
tests are stored in a separate project, that project is not searched. 
</li>
          <li>
The PexStore API has been renamed to PexObserve. 
</li>
          <li>
Pex is compatible with Code Contracts versions strictly newer than v1.1.20309.13.
Unfortunately, v1.1.20309.13 is the currently available version of Code <a href="http://research.microsoft.com/contracts" target="_blank">Contracts</a>.
The Code Contracts team is planning on a release soon. 
</li>
        </ul>
        <p>
 
</p>
        <p>
Happy Pexing!
</p>
        <img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=83fde01f-786e-456d-b1c4-c8dd52448e69" />
      </body>
      <title>Pex v0.10.40408.0: NUnit, MbUnit, xUnit.Net, Visual Basic.NET, F# and more…</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/04/10/PexV010404080NUnitMbUnitXUnitNetVisualBasicNETFAndMore.aspx</link>
      <pubDate>Fri, 10 Apr 2009 19:06:31 GMT</pubDate>
      <description>&lt;blockquote&gt; 
&lt;p&gt;
&lt;a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx" target="_blank"&gt;&lt;strong&gt;Download
the new version!&lt;/strong&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Today we’ve released a new release of &lt;a href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt; on
DevLabs and on our academic downloads. This highlights of this release are: &lt;a href="http://www.nunit.org" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://www.mbunit.com/" target="_blank"&gt;MbUnit&lt;/a&gt; and &lt;a href="http://xunit.codeplex.com/" target="_blank"&gt;xUnit.net&lt;/a&gt; support
out of the box, &lt;strong&gt;writing &lt;a href="http://research.microsoft.com/pex"&gt;parameterized
unit tests&lt;/a&gt; in VisualBasic.NET and F#, better &lt;a href="http://research.microsoft.com/contracts"&gt;Code
Contracts&lt;/a&gt; support&lt;/strong&gt;. As always, if we encourage you to send us feedback,
bugs, stories on our forums at &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/"&gt;http://social.msdn.microsoft.com/Forums/en-US/pex/threads/&lt;/a&gt; .
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://www.nunit.org" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://www.mbunit.com" target="_blank"&gt;MbUnit&lt;/a&gt; and &lt;a href="http://www.codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; supported
out of the box&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
Pex now supports MSTest, NUnit, MbUnit and xUnit.net out of the box. Pex will automatically
detect which framework you are using by inspecting the assembly reference list, and
automatically save the generated tests decorated with the correct attributes for that
framework. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_10.png" width="604" height="351" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The default test framework can also be specified through the global options (Tools
–&amp;gt; Options –&amp;gt; Pex –&amp;gt; enter the test framework name in TestFramework).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_7.png" width="604" height="257" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Writing Parameterized Unit Tests in VisualBasic.NET&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
While the Pex white box analysis engine works at the MSIL level, Pex only emits C#
code for now. In previous releases, this limitation made it impossible to use Pex
parameterized unit tests from non-C# code. In this release, we have worked around
this problem by automatically saving the generated tests in a ‘satellite’ C# project.
&lt;/p&gt;
&lt;p&gt;
Let’s see this with an example. The screenshot below shows a single VisualBasic.NET
test project with a Pex parameterized unit test:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image3.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image002_0dd1c4a7-6732-42b8-b6fe-76f7499e6a66.gif" width="604" height="237" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We can right-click in the HelloTest.Hello method and select “Run Pex Explorations”:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image7.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image004_31e0ecca-a518-4ec3-9ad4-3fef0bb58593.gif" width="305" height="91" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
At this point, Pex will start exploring the test in the background as usual. This
is where the new support comes in: When a generated test comes back to Visual Studio,
Pex will save it in a separate C# project automatically (after asking you where to
drop the new project):
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image19.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image006_324456a0-a756-4cfe-b9cb-e7eb8a9db8a0.gif" width="604" height="391" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The generated tests are now ready to be run just as any other unit tests!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Writing Parameterized Unit Tests from F#&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Similarly to VisualBasic.NET, we’ve made improvements in our infrastructure to enable
writing parameterized unit tests in &lt;strong&gt;F#&lt;/strong&gt;. Let’s see this with a familiar
example. We have a single F# library that has xUnit.net unit tests and reference Microsoft.Pex.Framework
(project Library2 below). In that project, we add a parameterized unit test (hello_test):
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image32%5b1%5d.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image008_709d95c3-12c4-4805-b549-2982d5341032.gif" width="604" height="235" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We can right-click on the &lt;strong&gt;test method name&lt;/strong&gt; and Pex will start the
exploration of that test in the background. Because of the limitations of the F# project
system, you &lt;strong&gt;absolutely&lt;/strong&gt; need to right-click on the&lt;strong&gt; method
name&lt;/strong&gt; in F# if you want contextual test selection to work. Because the project
is already referencing xunit.dll, Pex will also automatically detect that you are
using xUnit.net and use that framework. When the first test case comes back to VisualStudio,
Pex saves it in a separate C# project:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image39.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image010_69f5c0e9-4c03-4251-a79a-38c7ffbb3a19.gif" width="604" height="341" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The tests are saved in the generated test project and ready to be run by your favorite
test runner!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;PexObserve: Observing values, Asserting values&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We’ve completely re-factored the way values can be logged on the table or saved as
assertions in the generated tests. The following example shows various ways to log
and assert values:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_3.png" width="451" height="228" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the Observe method, we use the return value and out parameter output to automatically
log and assert those values. Additionally, we add “view input” on the fly to the parameter
table through the ValueForViewing method, and we add “check input” to be asserted
through the ValueAtEndOfTest method. After running Pex, we get the following results:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_4.png" width="373" height="63" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
As expected, input, ‘view input’, output and result show up in the parameter table.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_5.png" width="599" height="266" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the generated test, we see assertions for the return value, out parameters and
other values passed through the ValueAtEndOfTest method.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/contracts"&gt;Code Contracts&lt;/a&gt; : Reproducible
generated tests&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When Pex generates a unit test that relied on a runtime contract, Pex also adds a
check to the unit test which validates that the contracts have been injected into
the code by the contracts rewriter. If the code is not rewritten when re-executing
the unit test, it is marked as inconclusive. You will appreciate this behavior when
you run your unit tests both in Release and in Debug builds, which usually differ
in how contracts get injected.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="file:///C:\Users\jhalleux\AppData\Local\Temp\WindowsLiveWriter-429641856\supfiles659CA51\image43.png"&gt;&lt;b&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/clip_image012_32c70deb-1184-48c7-a1cd-16e1c19559d3.gif" width="604" height="177" /&gt;&lt;/b&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Code Contracts:&amp;#160; Automatic filtering of the contract violations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When Pex generates a test that violates a Code Contract pre-condition (i.e. Contract.Requires),
there are basically two scenarios: the precondition was on top of the stack and should
be considered as an expected exception; or it is a nested exception and should be
considered as a bug. Pex provides a default exception filtering that implements this
behavior.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;: simplified
syntax&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We’ve considerably simplified the syntax of stubs by removing the ‘this’ parameter
from the stub delegate definition. Let’s illustrate this with a test that stubs the
‘ReadAllText’ method of a fictitious ‘IFileSystem’ interface.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://research.microsoft.com/en-us/projects/stubs/stubexample.png" /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt;: generic
methods&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://research.microsoft.com/stubs" target="_blank"&gt;Stubs&lt;/a&gt; framework
now supports stubbing generic methods by providing particular instantiations of that
method. In the following example, the generic Bar&amp;lt;T&amp;gt; method is stubbed for the
particular Bar&amp;lt;int&amp;gt; instantiation:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb.png" width="435" height="119" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs and Pex: Pex will choose the stubs behavior by default&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
We provide a new custom attribute, PexChooseAsStubFallbackBehaviorAttribute, that
hooks Pex choices to the Stub fallback behavior. To illustrate what this means, let’s
modify slightly the example above by removing the stub of ReadAllText:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_1.png" width="455" height="216" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
If this test was to be run without the PexChooseAsStubFallbackBehavior attribute,
it would throw a StubNotImplementedException. However, with the PexChooseAsStubFallbackBehavior
attribute, the fallback behavior calls into PexChoose to ask Pex for a new string.
In this example in particular, on each call to ReadAllText, Pex will generate a new
string for the result. You can see this string as a new parameter to the parameterized
unit test. Therefore, when we run this test under Pex, we see different behavior happening,
including the “hello world” file:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.dotnetwiki.org/content/binary/WindowsLiveWriter/Pexv0.10.40408.0NUnitMbUnitx.NETFandmore_14623/image_thumb_2.png" width="584" height="90" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Note that all the necessary attributes are added at the assembly level by the Pex
Wizard.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Miscellanous bug fixes and improvements&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
[fixed] Dialogs do not render correctly under high DPI 
&lt;/li&gt;
&lt;li&gt;
When a generic parameterized unit tests does not have any generic argument instantiations,
Pex makes a guess for you. 
&lt;/li&gt;
&lt;li&gt;
When a test parameter is an interface or an abstract class, Pex now searches the known
assemblies for implementations and concrete classes. In particular, that means that
Pex will often automatically use the automatically generated Stubs implementations
for interfaces or abstract classes. 
&lt;/li&gt;
&lt;li&gt;
Static parameterized unit tests are supported (if static tests are supported by your
test framework) 
&lt;/li&gt;
&lt;li&gt;
Better solving of decimal and floating point constraints. We will report on the details
later. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Breaking Changes&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The PexFactoryClassAttribute is no longer needed and has been removed. Now, Pex will
pick up object factory methods marked with the PexFactoryMethodAttribute from any &lt;i&gt;static
class&lt;/i&gt; in the test project containing the parameterized unit tests. If the generated
tests are stored in a separate project, that project is not searched. 
&lt;/li&gt;
&lt;li&gt;
The PexStore API has been renamed to PexObserve. 
&lt;/li&gt;
&lt;li&gt;
Pex is compatible with Code Contracts versions strictly newer than v1.1.20309.13.
Unfortunately, v1.1.20309.13 is the currently available version of Code &lt;a href="http://research.microsoft.com/contracts" target="_blank"&gt;Contracts&lt;/a&gt;.
The Code Contracts team is planning on a release soon. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Happy Pexing!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=83fde01f-786e-456d-b1c4-c8dd52448e69" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,83fde01f-786e-456d-b1c4-c8dd52448e69.aspx</comments>
      <category>Code Contracts</category>
      <category>MbUnit</category>
      <category>Pex</category>
      <category>RiSE</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://blog.dotnetwiki.org/Trackback.aspx?guid=1969e7c2-fd47-43cd-83e9-4f11889dd99d</trackback:ping>
      <pingback:server>http://blog.dotnetwiki.org/pingback.aspx</pingback:server>
      <pingback:target>http://blog.dotnetwiki.org/PermaLink,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</pingback:target>
      <dc:creator>Jonathan de Halleux</dc:creator>
      <wfw:comment>http://blog.dotnetwiki.org/CommentView,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.dotnetwiki.org/SyndicationService.asmx/GetEntryCommentsRss?guid=1969e7c2-fd47-43cd-83e9-4f11889dd99d</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Introduction to the Stubs Framework</title>
      <guid isPermaLink="false">http://blog.dotnetwiki.org/PermaLink,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</guid>
      <link>http://blog.dotnetwiki.org/2009/01/10/IntroductionToTheStubsFramework.aspx</link>
      <pubDate>Sat, 10 Jan 2009 15:41:32 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a target="_blank" href="http://blog.dotnetwiki.org/PexGetsAStubsFrameworkISaidStubsNotMocks.aspx"&gt;Stubs&lt;/a&gt; is
a framework for generating stubs (that &lt;a target="_blank" href="http://blog.dotnetwiki.org/PexGetsAStubsFrameworkISaidStubsNotMocks.aspx"&gt;we
announced earlier with Pex&lt;/a&gt;). The framework generates stubs (not mocks) that are 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
lightweight, i.e. relying on delegates only, 
&lt;/li&gt;
&lt;li&gt;
strongly typed, i.e. no magic strings – refactoring friendly, 
&lt;/li&gt;
&lt;li&gt;
source code generated, i.e. no dynamic code or expression trees, 
&lt;/li&gt;
&lt;li&gt;
great debugging experience, i.e. break and step through stubs, 
&lt;/li&gt;
&lt;li&gt;
minimalistic API (there is almost none), 
&lt;/li&gt;
&lt;li&gt;
friendly for &lt;a target="_blank" href="http://research.microsoft.com/pex"&gt;Pex&lt;/a&gt;! 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
More details about Stubs are also available in the &lt;a target="_blank" href="http://research.microsoft.com/en-us/projects/pex/stubs.pdf"&gt;stubs
reference document&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Quick Start&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Let’s start from a simple interface &lt;font face="Courier New"&gt;IFileSystem &lt;/font&gt;for
which we want to write stubs:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public interface &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem &lt;/span&gt;{ &lt;span style="color: blue;"&gt;void &lt;/span&gt;WriteAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName, &lt;span style="color: blue;"&gt;string &lt;/span&gt;content); &lt;span style="color: blue;"&gt;string &lt;/span&gt;ReadAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName);
}&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;strong&gt;Stubs&lt;/strong&gt; relies solely on delegates to attach behaviors, and leverages
the lambda syntax from C# 3.0 to accomplish pretty much anything:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: green;"&gt;// SFileSystem was generated
by Stubs and stubs IFileSystem &lt;/span&gt;&lt;span style="color: blue;"&gt;var &lt;/span&gt;stub = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&lt;/span&gt;(); &lt;span style="color: green;"&gt;//
always returns “...” &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; &lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;; &lt;span style="color: green;"&gt;//
expectations: checks file = “foo.txt” &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; { &lt;span style="color: rgb(43, 145, 175);"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: rgb(163, 21, 21);"&gt;"foo.txt"&lt;/span&gt;,
file); &lt;span style="color: blue;"&gt;return &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;;
}; &lt;span style="color: green;"&gt;// storing side effects in closures: written saves
content &lt;/span&gt;&lt;span style="color: blue;"&gt;string &lt;/span&gt;written = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;
stub.WriteAllText = (me, file, content) =&gt; written = content; &lt;span style="color: green;"&gt;//
hey, we can do whatever we want! &lt;/span&gt;stub.ReadAllText = (me, file) =&gt; { &lt;span style="color: blue;"&gt;if &lt;/span&gt;(file
== &lt;span style="color: blue;"&gt;null&lt;/span&gt;) &lt;span style="color: blue;"&gt;throw new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ArgumentNullException&lt;/span&gt;(); &lt;span style="color: blue;"&gt;return &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"..."&lt;/span&gt;;
};&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: green;"&gt;// downcast to the interface to use
it &lt;/span&gt;IFileSystem fs = stubs;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Anything is possible… as long as C# (or your favorite language) allows it.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Anatomy of a Stub&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Each stubbed method has an associated field delegate that can be set freely (e.g. &lt;font face="Courier New"&gt;WriteAllText &lt;/font&gt;and &lt;font face="Courier New"&gt;ReadAllText&lt;/font&gt;).
If this delegate field is set, it will used when the method is called; otherwize a
default action occurs. Let’s see this with a simplified stub of the &lt;font face="Courier New"&gt;IFileSystem &lt;/font&gt;interface, &lt;font face="Courier New"&gt;SFileSystem&lt;/font&gt;,
which shows how the &lt;font face="Courier New"&gt;IFileSystem.WriteAllText&lt;/font&gt; is implemented:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;class &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem &lt;/span&gt;: &lt;span style="color: rgb(43, 145, 175);"&gt;StubBase&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&gt;&gt;
, &lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem &lt;/span&gt;{ &lt;span style="color: blue;"&gt;public &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;SFileSystem&gt;, &lt;span style="color: blue;"&gt;string&lt;/span&gt;, &lt;span style="color: blue;"&gt;string&lt;/span&gt;&gt;
WriteAllText; // attach here &lt;span style="color: blue;"&gt;void &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IFileSystem&lt;/span&gt;.WriteAllText(&lt;span style="color: blue;"&gt;string &lt;/span&gt;fileName, &lt;span style="color: blue;"&gt;string &lt;/span&gt;content)
{ &lt;span style="color: blue;"&gt;var &lt;/span&gt;stub = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.WriteAllText; &lt;span style="color: blue;"&gt;if &lt;/span&gt;(stub
!= &lt;span style="color: blue;"&gt;null&lt;/span&gt;) stub(&lt;span style="color: blue;"&gt;this&lt;/span&gt;,
fileName, content); // your code executed here &lt;span style="color: blue;"&gt;else this&lt;/span&gt;.DefaultStub.VoidResult(&lt;span style="color: blue;"&gt;this&lt;/span&gt;);
} }&lt;/pre&gt;
&lt;/blockquote&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The actual generated code may look more complicated because it contains custom attributes
for debugging, comments and globally qualified types to avoid name clashing:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb.png" width="604" border="0" height="387"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Code generation: How does it work?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Stubs&lt;/strong&gt; is a single file generator that pre-generates stubs to source
code. &lt;strong&gt;Stubs&lt;/strong&gt; also monitors the build and regenerates the source code
when a change occurs.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_3.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_3.png" width="243" border="0" height="277"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The stub generation is configured through an XML file (&lt;strong&gt;.stubx&lt;/strong&gt; file)
that contains which code and how it should be generated. The generated code is saved
in a ‘Designer’ file, similarly to other code generation tools (type dataset etc…). 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_4.png" width="476" border="0" height="71"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Great debugging experience&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
A cool side effect of simply using delegates: you can step through and debug your
stubs! This is usually not the case with mock framework using dynamic code. Below,
you can see that one can set breakpoints in the body of a stub and debug as usual.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_5.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blog.dotnetwiki.org/images/StubspartIGettingStarted_F368/image_thumb_5.png" width="687" border="0" height="323"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Where do I get it?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The Stubs framework comes with Pex but you can use it in any unit testing activity.
It provides a simple lightweight alternative to define stub for testing. Pex can be
downloaded from &lt;a href="http://research.microsoft.com/pex"&gt;http://research.microsoft.com/pex&lt;/a&gt; .
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.dotnetwiki.org/aggbug.ashx?id=1969e7c2-fd47-43cd-83e9-4f11889dd99d" /&gt;</description>
      <comments>http://blog.dotnetwiki.org/CommentView,guid,1969e7c2-fd47-43cd-83e9-4f11889dd99d.aspx</comments>
      <category>Pex</category>
      <category>Stubs</category>
      <category>Testing</category>
    </item>
  </channel>
</rss>