<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Peter Huene's Blog</title><subtitle type="html">Code Coverage, Test Impact, and IntelliTrace</subtitle><id>http://blogs.msdn.com/phuene/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/phuene/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2007-05-02T13:38:00Z</updated><entry><title>Test Impact Analysis with Microsoft Test Manager 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2010/03/12/test-impact-analysis-with-microsoft-test-manager-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2010/03/12/test-impact-analysis-with-microsoft-test-manager-2010.aspx</id><published>2010-03-12T18:55:53Z</published><updated>2010-03-12T18:55:53Z</updated><content type="html">&lt;p&gt;So I’ve had a little bit of a dry spell with respect to blog entries of late.&amp;#160; I was planning on (eventually) writing a detailed walkthrough of using test impact analysis with Microsoft Test Manager to view impact to manual tests.&amp;#160; However, I stumbled upon &lt;a href="http://blog.nfocus.co.uk/2010/03/vs2010-test-impact-one-giant-leap-for.html"&gt;Danny Crone from nFocus’ video&lt;/a&gt; that covers it in more detail than what I was going to do.&amp;#160; So check out Danny’s video if you’re interested in seeing test impact analysis in action with MTM and Team Foundation Build.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9977680" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /><category term="Test Impact" scheme="http://blogs.msdn.com/phuene/archive/tags/Test+Impact/default.aspx" /><category term="Team Foundation Build" scheme="http://blogs.msdn.com/phuene/archive/tags/Team+Foundation+Build/default.aspx" /></entry><entry><title>Test Impact with Team Foundation Build 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2009/12/09/test-impact-with-team-foundation-build-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2009/12/09/test-impact-with-team-foundation-build-2010.aspx</id><published>2009-12-09T23:36:43Z</published><updated>2009-12-09T23:36:43Z</updated><content type="html">&lt;p&gt;So in my &lt;a href="http://blogs.msdn.com/phuene/archive/2009/12/07/test-impact-analysis-in-visual-studio-2010.aspx"&gt;last blog entry&lt;/a&gt;, I touched upon how you could use the Test Impact View in Visual Studio 2010.&amp;#160; Today’s topic is how to use the test impact feature with Team Foundation Build 2010.&amp;#160; Team Foundation Build 2010 is part of Team Foundation Server 2010 and has many new features, including the very cool &amp;quot;Gated Check-in” feature that allows you to configure a build to validate a shelveset before it ever gets checked into the product.&amp;#160; Among those many new features is support for test impact analysis.&amp;#160; Let’s walk through creating a simple class library, creating unit tests, creating a build definition, and modifying source code to view test impact in Team Foundation Build 2010.&lt;/p&gt;  &lt;p&gt;To get started, let’s create a new C# class library project called “DemoLibrary” (a more ingenious name there never was):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/new_project_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="new_project" border="0" alt="new_project" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/new_project_thumb.png" width="515" height="306" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note that I’ve checked the “Add to source control” checkbox.&amp;#160; This will prompt us to add the solution to Team Foundation Server after the project is created, like so:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/add_to_source_control_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="add_to_source_control" border="0" alt="add_to_source_control" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/add_to_source_control_thumb.png" width="308" height="378" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here, I am adding the solution to the “Demo Project” team project I already created on my Team Foundation Server.&amp;#160; Next, I renamed the generic “Class1.cs” to “DemoClass.cs”, which refactored &lt;em&gt;Class1&lt;/em&gt; to &lt;em&gt;DemoClass&lt;/em&gt;.&amp;#160; Here’s what my brilliant demo library source looks like:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; DemoLibrary&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; &lt;font color="#2c92af"&gt;DemoClass&lt;/font&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestMe()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;             &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;TestMe() was called.&amp;quot;&lt;/font&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;So now that we have a rather useless library to test, let’s create a unit test for the &lt;em&gt;TestMe&lt;/em&gt; method.&amp;#160; Right click inside of &lt;em&gt;TestMe&lt;/em&gt; in the editor and select “Create Unit Tests…”.&amp;#160; Doing so will bring up this dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/create_unit_tests_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="create_unit_tests" border="0" alt="create_unit_tests" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/create_unit_tests_thumb.png" width="394" height="251" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After clicking the OK button, it will prompt you for a name of the new test project.&amp;#160; Let’s call our test project “DemoLibraryTests”.&amp;#160; Having “Tests” in the name will come in handy later on.&amp;#160; Let’s change the code for the unit test to simply:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; DemoLibrary;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.VisualStudio.TestTools.UnitTesting;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; DemoLibraryTests&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     [&lt;font color="#2c92af"&gt;TestClass&lt;/font&gt;()]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; &lt;font color="#2c92af"&gt;DemoClassTest&lt;/font&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         [&lt;font color="#2c92af"&gt;TestMethod&lt;/font&gt;()]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestMeTest()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;font color="#2c92af"&gt;DemoClass&lt;/font&gt;.TestMe();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, all the unit test does is call the &lt;em&gt;TestMe&lt;/em&gt; method in the &lt;em&gt;DemoClass&lt;/em&gt; class.&amp;#160; As &lt;em&gt;TestMe&lt;/em&gt; never throws and the test never asserts, this test should always pass.&amp;#160; Obviously it’s not a useful test, but this walkthrough is more about how to use the test impact feature than how to properly test your source code.&amp;#160; Now let’s turn on test impact locally by changing the active test settings to the “Trace and Test Impact” settings (the “trace” part of the name is for IntelliTrace; if the test fails, you’ll get an .iTrace file you can examine for diagnostic events and exceptions):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/select_active_test_settings_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="select_active_test_settings" border="0" alt="select_active_test_settings" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/select_active_test_settings_thumb.png" width="577" height="459" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now that we’ve switched the active test settings to collect test impact data, let’s run the test locally before checking in.&amp;#160; Once we’ve verified the test passes, check the files in.&amp;#160; Right click on the solution in Solution Explorer and select “Check In…” to bring up this dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/checking_in_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="checking_in" border="0" alt="checking_in" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/checking_in_thumb.png" width="412" height="290" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After checking in the files, it’s time to setup a Team Foundation Build to build our projects and run tests.&amp;#160; To do so, bring up Team Explorer, right click on “Builds” and select “New Build Definition…”, to bring up the build definition editor:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/set_drop_location_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="set_drop_location" border="0" alt="set_drop_location" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/set_drop_location_thumb.png" width="572" height="476" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The first thing you’ll need to do is give the build definition a name on the “General” tab.&amp;#160; I gave my build definition the creative name of “Demo Build”.&amp;#160; The next thing to do is to set the build drop location on the “Build Defaults” tab, shown above.&amp;#160; The build drop location is a share you would like the builds published to.&amp;#160; The share needs to grant read/write privileges to the identity of the build agent service so that it can publish the build outputs.&lt;/p&gt;

&lt;p&gt;Next, we need to change properties in the “Process” tab in the build definition editor.&amp;#160; This section controls what gets built and tested.&amp;#160; There are three important properties for us in this scenario: Items to Build (i.e. what solutions/projects to build), Automated Tests (i.e. what tests to run), and Analyze Test Impact (i.e. should test impact analysis be performed?&amp;#160; The default is yes.).&amp;#160; Clicking on the “…” button in the “Items to Build” property brings up this dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/items_to_build_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="items_to_build" border="0" alt="items_to_build" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/items_to_build_thumb.png" width="391" height="309" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;With the build of Visual Studio 2010 I’m using to walkthrough this scenario, Team Foundation Build was smart enough to pre-populate this with the solution we’re working on already.&amp;#160; I’m not sure if this functionality is in Beta 2 or not, so I’m displaying this screenshot to show where you would select the solution to build.&amp;#160; Next, let’s configure what tests to run by clicking on the “…” button in the “Automated Tests” property:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/add_edit_test_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="add_edit_test" border="0" alt="add_edit_test" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/add_edit_test_thumb.png" width="394" height="380" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Again, the build of Team Foundation Build I’m using was smart enough to default to running all tests in files that match *test*.dll.&amp;#160; Because we named our unit test project “DemoLibraryTests”, Team Foundation Build will automatically run our tests without us changing anything.&amp;#160; By default, Team Foundation Build will run tests using the Local.testsettings file.&amp;#160; This file will not have the test impact diagnostic data adapter enabled.&amp;#160; To enable test impact data collection, you need to either enable the test impact diagnostic data adapter in Local.testsettings, or switch the test settings to one that already has it enabled.&amp;#160; The test project already created a test settings file that supports test impact data collection, so let’s click the Browse button above to change it to TraceAndTestImpact.testsettings:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/browse_for_test_impact_settings_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="browse_for_test_impact_settings" border="0" alt="browse_for_test_impact_settings" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/browse_for_test_impact_settings_thumb.png" width="343" height="281" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once this is done, save the new build definition.&amp;#160; A “Demo Build” node should appear under the “Builds” node in Team Explorer.&amp;#160; Let’s queue up a new build by right clicking on the “Demo Build” node and selecting “Queue New Build…”.&amp;#160; This brings up a dialog to override build definition defaults if so desired.&amp;#160; Just click the “Queue” button to queue the build using the defaults provided in the build definition.&amp;#160; Double click on the build in progress in Build Explorer.&amp;#160; This will show you what the build is currently doing.&amp;#160; The build should succeed and the build summary page should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/build_success_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="build_success" border="0" alt="build_success" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/build_success_thumb.png" width="568" height="474" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We see here that our unit test ran successfully and no tests were impacted.&amp;#160; As this is the very first build of this build definition, there won’t be any impacted tests because tests have never been run with test impact data collected.&amp;#160; Now comes the fun part: changing the code.&amp;#160; Open up DemoClass.cs and simply change the “TestMe() was called.” string to something different; this will automatically check out the file for edit.&amp;#160; I chose to change the period to an exclamation point.&amp;#160; An innocuous change, but even a seemingly innocuous change can cause tests to fail.&amp;#160; Build the solution and view the test impact view by going to Test –&amp;gt; Windows –&amp;gt; Test Impact View.&amp;#160; Test Impact View should have detected the code change and recommended that the unit test be run, like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/vs_impacted_test_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="vs_impacted_test" border="0" alt="vs_impacted_test" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/vs_impacted_test_thumb.png" width="574" height="479" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As you can see, it does recommend TestMeTest be run to verify the change I made to TestMe.&amp;#160; Let’s click the “Run Tests” link in the Test Impact view to run the impacted tests.&amp;#160; The test should pass.&amp;#160; Now we’re ready to check in the change.&amp;#160; Right click on the solution in Solution Explorer and select “Check In…” again to bring up this dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/check_in_again_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="check_in_again" border="0" alt="check_in_again" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/check_in_again_thumb.png" width="428" height="302" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Check in the change.&amp;#160; Queue up a new “Demo Build” build.&amp;#160; During the build, a special activity will notice the change to &lt;em&gt;TestMe&lt;/em&gt; and record that the unit test was impacted for that build.&amp;#160; You will find this in the Test Impact section of the build summary page:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/impact_tests_in_build_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="impact_tests_in_build" border="0" alt="impact_tests_in_build" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/impact_tests_in_build_thumb_1.png" width="582" height="485" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;This shows that the unit test was impacted by 1 code change.&amp;#160; What if the change had actually caused the test to fail?&amp;#160; Wouldn’t it be nice if we could easily figure out what changes might have caused the test to fail?&amp;#160; That’s where the “1 code change(s)” link shown above comes in.&amp;#160; Clicking this will give you more detail in what code changes likely caused the test to be impacted.&amp;#160; Let’s click the link to bring up the code changes dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/impacting_code_changes_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="impacting_code_changes" border="0" alt="impacting_code_changes" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/impacting_code_changes_thumb.png" width="505" height="433" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As we can see here, the method &lt;em&gt;DemoLibrary.DemoClass.TestMe()&lt;/em&gt; was modified and this caused the test to be impacted.&amp;#160; We then get a list of all changesets that went into the build that modified the file.&amp;#160; We can then go through each changeset to identify which may have broken the test.&amp;#160; Clicking the “Compare Changes” link will compare only the file containing an impacting code change with the previous version:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/compare_changes_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="compare_changes" border="0" alt="compare_changes" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactwithTeamFoundationBuild2010_C98B/compare_changes_thumb.png" width="584" height="419" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here we see I changed the ‘.’ to a ‘!’ which changed &lt;em&gt;TestMe&lt;/em&gt; and ultimately impacted the test in question.&lt;/p&gt;

&lt;p&gt;Let’s end this long walkthrough here.&amp;#160; Hopefully you find this information useful in setting up test impact analysis in Team Foundation Build 2010.&amp;#160; My next related blog entry will be using the test impact analysis feature from the new Microsoft Test and Lab Management product for manual tests.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9934890" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /><category term="Test Impact" scheme="http://blogs.msdn.com/phuene/archive/tags/Test+Impact/default.aspx" /><category term="Team Foundation Build" scheme="http://blogs.msdn.com/phuene/archive/tags/Team+Foundation+Build/default.aspx" /></entry><entry><title>Test Impact Analysis in Visual Studio 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2009/12/07/test-impact-analysis-in-visual-studio-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2009/12/07/test-impact-analysis-in-visual-studio-2010.aspx</id><published>2009-12-08T01:31:59Z</published><updated>2009-12-08T01:31:59Z</updated><content type="html">&lt;p&gt;One of the new features you’ll find in Visual Studio 2010 (Premium and Ultimate editions) is test impact analysis.&amp;#160; Inside of Visual Studio, this feature is used to immediately inform the developer of what tests they should run to verify the code changes they are making.&amp;#160; You can also find the feature as part of Team Foundation Build and Microsoft Test and Lab Management, but I will limit today’s blog post to what you’ll find in Visual Studio.&lt;/p&gt;  &lt;p&gt;I should call out the fact that this feature only supports managed code (e.g. VB.NET,C#,C++/CLI) in 2010.&amp;#160; Native code is not yet supported, but it is something we would like to add support for in a future release.&lt;/p&gt;  &lt;p&gt;To get started, let’s create a C# unit test project called “DemoProject”.&amp;#160; Here’s what it might look like with some additional unit test code:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/new_project_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="new_project" border="0" alt="new_project" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/new_project_thumb.png" width="533" height="412" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see, I’ve defined two tests that each call a different private method.&amp;#160; This is obviously a very contrived example, but hopefully I’ll be able to demonstrate how this is applicable to your own source base by the end of this blog entry.&lt;/p&gt;  &lt;p&gt;Next, let’s bring up the Test Impact View.&amp;#160; This is a new tool window that exposes the test impact analysis feature in Visual Studio.&amp;#160; You can show the Test Impact View by &lt;strong&gt;selecting&lt;/strong&gt; the “Test –&amp;gt; Windows –&amp;gt; Test Impact View” menu item, as seen here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/menu_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="menu" border="0" alt="menu" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/menu_thumb.png" width="529" height="422" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It should look something like this (note, the images here may display slightly different text than what you’ll find in Beta 2 because these are from a newer build):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/test_impact_view_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="test_impact_view" border="0" alt="test_impact_view" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/test_impact_view_thumb.png" width="529" height="409" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;I’ve highlighted an important link in the view above.&amp;#160; This link is visible when the active test settings does not have the “test impact diagnostic data adapter” (that’s a mouthful, isn’t it?) enabled.&amp;#160; Diagnostic data adapters allow the capturing of data while tests are executing.&amp;#160; You’ll also find a diagnostic data adapter for IntelliTrace, code coverage, and more, in the test settings.&amp;#160; The way the test impact diagnostic data adapter works is by dynamically instrumenting your code at runtime to record what was executed by each test.&amp;#160; Each test that executed will produce its own “testimpact.xml” file attachment.&amp;#160; The contents of this file are not something I’m going to discuss at this time.&lt;/p&gt;  &lt;p&gt;Clicking the link will enable test impact data collection when tests are run.&amp;#160; Let’s &lt;strong&gt;click&lt;/strong&gt; the link and then run all tests by &lt;strong&gt;selecting&lt;/strong&gt; the “Test –&amp;gt; Run –&amp;gt; All Tests In Solution” menu item, to arrive at this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/collected_data_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="collected_data" border="0" alt="collected_data" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/collected_data_thumb.png" width="529" height="409" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;One thing I’ll mention is that we only collect data for passing tests.&amp;#160; If a test fails, we’ll continue to use the last set of data we successfully collected.&amp;#160; Now comes the interesting part: making a change to the source code.&amp;#160; Let’s &lt;strong&gt;insert&lt;/strong&gt; the following line into &lt;em&gt;CalledByFirstTest&lt;/em&gt; and then &lt;strong&gt;build&lt;/strong&gt; the solution:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; System.&lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;Hello world&amp;quot;&lt;/font&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Test impact analysis will analyze, in the background, the resulting assemblies produced by the build to look for meaningful changes to method instructions or data such as strings.&amp;#160; This means that changes to comments or changes that are optimized away by the compiler (i.e. foo + 10 =&amp;gt; foo + 5 + 5) are ignored by test impact analysis.&amp;#160; Since we know &lt;em&gt;TestMethod1&lt;/em&gt; calls the changed method &lt;em&gt;CalledByFirstTest&lt;/em&gt;, the tool window immediately recommends that we run &lt;em&gt;TestMethod1&lt;/em&gt; to verify the change:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/after_first_change_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="after_first_change" border="0" alt="after_first_change" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/after_first_change_thumb.png" width="528" height="408" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s make the same change to the other private method and &lt;strong&gt;build&lt;/strong&gt; again:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/after_second_change_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="after_second_change" border="0" alt="after_second_change" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/after_second_change_thumb.png" width="530" height="410" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We now have two tests impacted.&amp;#160; The selected impacted test is &lt;em&gt;TestMethod1&lt;/em&gt; in and the lower pane in the view is showing the code changes test impact analysis thinks is currently impacting the test.&amp;#160; If we selected the other impacted test, we would see &lt;em&gt;CalledBySecondTest&lt;/em&gt; in the lower pane, as expected.&lt;/p&gt;

&lt;p&gt;I’ve highlighted three buttons at the top of the Test Impact View in the image above.&amp;#160; From left to right: the first button is for displaying impacted tests (this is the default view), the second is for displaying the code changes remaining to be verified, and the third tab is for showing tests known to call a method.&amp;#160; &lt;strong&gt;Clicking&lt;/strong&gt; on the second button from the left results in this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/code_changes_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="code_changes" border="0" alt="code_changes" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/code_changes_thumb.png" width="528" height="408" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here we see the two methods we changed.&amp;#160; Selecting a code change shows the tests that need to run to verify it.&amp;#160; Once all impacted tests are run successfully, the code change will no longer show up in this list until the code is changed again.&amp;#160; To display tests known to call a particular method,&lt;strong&gt; right click&lt;/strong&gt; inside of the method in the editor and &lt;strong&gt;select&lt;/strong&gt; “Show Calling Tests”, like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/show_calling_tests_menu_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="show_calling_tests_menu" border="0" alt="show_calling_tests_menu" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/show_calling_tests_menu_thumb.png" width="530" height="412" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Clicking this menu item will switch the test impact view into the “show calling tests” mode:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/show_calling_tests_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="show_calling_tests" border="0" alt="show_calling_tests" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/show_calling_tests_thumb.png" width="530" height="410" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The view displays a list of tests known (i.e. have been run with test impact data collection enabled) to call the method in question.&amp;#160; If you frequently run unit tests inside of Visual Studio, this is a good way to quickly tell if the method you’re modifying will impact tests if it is changed.&amp;#160; Now let’s run all impacted tests by &lt;strong&gt;selecting&lt;/strong&gt; “Test –&amp;gt; Run –&amp;gt; All Impacted Tests” menu item or by using the keyboard shortcut (Ctrl+R,Y).&amp;#160; The two tests will run successfully, shown here:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/done_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="done" border="0" alt="done" src="http://blogs.msdn.com/blogfiles/phuene/WindowsLiveWriter/TestImpactAnalysisinVisualStudio2010_F686/done_thumb.png" width="525" height="406" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As both tests have run successfully, the number of impacted tests falls to zero and there are no outstanding code changes to verify.&amp;#160; If you change the methods again, the test impact view will display what needs to be run to verify the changes.&lt;/p&gt;

&lt;p&gt;As I previously stated, this example is a rather silly one: we only use a single test project and the code being modified is in the test class itself.&amp;#160; In practice, you may have a large source base of code and a large number of tests that test your code.&amp;#160; If tests are run with test impact data collection enabled, the tests exist in the current solution context, and the code being modified also exists in a project in the current solution, then the test impact view will recommend what tests to run when you make your code changes.&lt;/p&gt;

&lt;p&gt;I encourage you to play around with the feature beyond what is covered in this blog entry, such as with &lt;a href="http://blogs.msdn.com/mathew_aniyan/archive/2009/11/05/tutorial-coded-ui-test-beta2.aspx"&gt;Coded UI tests&lt;/a&gt; (another new VS 2010 feature).&amp;#160; I think it’s rather neat to be able to record UI tests, run them with test impact data collection enabled, make changes to methods that are traditionally hard to test via a unit test (e.g. some UI event you can’t mock up easily) and build, hit Ctrl+R,Y (run all impacted tests), and then watch your application be UI tested.&amp;#160; Enjoy.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9933846" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /><category term="Test Impact" scheme="http://blogs.msdn.com/phuene/archive/tags/Test+Impact/default.aspx" /></entry><entry><title>Programmatic Code Coverage Data Merging in Visual Studio 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2009/12/04/programmatic-code-coverage-data-merging-in-visual-studio-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2009/12/04/programmatic-code-coverage-data-merging-in-visual-studio-2010.aspx</id><published>2009-12-04T23:40:45Z</published><updated>2009-12-04T23:40:45Z</updated><content type="html">&lt;p&gt;In my &lt;a href="http://blogs.msdn.com/phuene/archive/2009/12/01/programmatic-coverage-analysis-in-visual-studio-2010.aspx"&gt;last post&lt;/a&gt;, I demonstrated how you could use the coverage analysis assembly to analyze coverage files.&amp;#160; Today I will quickly cover how to programmatically merge multiple coverage files together.&amp;#160; This replicates the functionality that the code coverage results tool window has for merging coverage data from multiple test runs together.&amp;#160; The following assumes you’ve read the instructions in the previous post to reference the analysis assembly and use the &lt;em&gt;Microsoft.VisualStudio.Coverage.Analysis&lt;/em&gt; namespace.&lt;/p&gt;  &lt;p&gt;This function joins coverage files together into a single &lt;em&gt;CoverageInfo&lt;/em&gt; using the Visual Studio 2010 API:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; JoinCoverageFiles(&lt;font color="#2c92af"&gt;IEnumerable&lt;/font&gt;&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; files)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (files == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;font color="#2c92af"&gt;ArgumentNullException&lt;/font&gt;(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;files&amp;quot;&lt;/font&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// This will represent the joined coverage files&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; result = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; file &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; files)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// Create from the current file&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;             &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; current = &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt;.CreateFromFile(file);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;// First time through, assign to result&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;                 result = current;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;continue&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// Not the first time through, join the result with the current&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;             &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; joined = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum25"&gt;  25:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum26"&gt;  26:&lt;/span&gt;                 joined = &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt;.Join(result, current);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum27"&gt;  27:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum28"&gt;  28:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum29"&gt;  29:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum30"&gt;  30:&lt;/span&gt;                 &lt;span style="color: #008000"&gt;// Dispose current and result&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum31"&gt;  31:&lt;/span&gt;                 current.Dispose();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum32"&gt;  32:&lt;/span&gt;                 current = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum33"&gt;  33:&lt;/span&gt;                 result.Dispose();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum34"&gt;  34:&lt;/span&gt;                 result = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum35"&gt;  35:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum36"&gt;  36:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum37"&gt;  37:&lt;/span&gt;             result = joined;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum38"&gt;  38:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum40"&gt;  40:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (&lt;font color="#2c92af"&gt;Exception&lt;/font&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum41"&gt;  41:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum42"&gt;  42:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum43"&gt;  43:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum44"&gt;  44:&lt;/span&gt;             result.Dispose();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum45"&gt;  45:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum46"&gt;  46:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum47"&gt;  47:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum48"&gt;  48:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum49"&gt;  49:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum50"&gt;  50:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This function could be called like this:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; info = JoinCoverageFiles(files))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #008000"&gt;// Dump out the info like you would if it weren't joined&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (&lt;font color="#2c92af"&gt;CoverageAnalysisException&lt;/font&gt; ex)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(ex);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;One thing I left out in my previous post’s examples is &lt;em&gt;CoverageAnalysisException&lt;/em&gt;.&amp;#160; This is the base type for exceptions thrown by the analysis engine, so it will be one you will want to catch when using the analysis API.&amp;#160; Analysis exceptions are usually the result of a missing instrumented module (&lt;em&gt;ImageNotFoundException)&lt;/em&gt; or .pdb file (&lt;em&gt;SymbolsNotFoundException)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;How does joining two coverage files work under the covers?&amp;#160; It’s rather simple, actually.&amp;#160; When joining two coverage files together, we first union the modules together in the two coverage files.&amp;#160; Remember the &lt;em&gt;ICoverageModule.Signature&lt;/em&gt; and &lt;em&gt;ICoverageModule.SignatureAge&lt;/em&gt; properties?&amp;#160; These two properties are the unique identity of the module.&amp;#160; If the module is found in both of the coverage files we simply bitwise OR their coverage buffers together to arrive at the merged coverage data.&amp;#160; If a module is only found in one coverage file, we use the coverage buffer that was collected for it as is.&lt;/p&gt;

&lt;p&gt;As you might notice from this scheme, we will only merge module data together for modules that are identical.&amp;#160; When you instrument a module, we record the original file’s signature data in the instrumented module.&amp;#160; This means you can instrument an original module multiple times and merge the data between different instrumented copies together, provided that each instrumentation was performed the same way.&amp;#160; However, once the original module is rebuilt, you can no longer merge coverage data collected for the old version with data collected from the newer version.&amp;#160; When you attempt to do so, you’ll get two modules of the same name in the resulting coverage data distinguished by the time they were built.&amp;#160; In the future we hope to do a better job when merging coverage data between different builds of the same module.&lt;/p&gt;

&lt;p&gt;Please note that what I’ve described here is specific to Visual Studio 2010.&amp;#160; Earlier versions used a weaker heuristic to determine if module data can be merged together, sometimes resulting in undesirable behavior.&amp;#160; With 2010, you get a consistent merge every time, provided the coverage data came from the same original module.&lt;/p&gt;

&lt;p&gt;Well, this is it for my code coverage blog posts for a while.&amp;#160; My next series of posts will be a walk through of the test impact features in Visual Studio 2010, including a walk through of how to use it from Team Foundation Build and the new Microsoft Test and Lab Management product.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9932835" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Code Coverage" scheme="http://blogs.msdn.com/phuene/archive/tags/Code+Coverage/default.aspx" /><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /></entry><entry><title>Programmatic Coverage Analysis in Visual Studio 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2009/12/01/programmatic-coverage-analysis-in-visual-studio-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2009/12/01/programmatic-coverage-analysis-in-visual-studio-2010.aspx</id><published>2009-12-01T19:31:00Z</published><updated>2009-12-01T19:31:00Z</updated><content type="html">&lt;p&gt;As hinted upon in my last post, today’s entry will be on how to programmatically perform analysis on a Visual Studio coverage file in Visual Studio 2010.&lt;/p&gt;  &lt;p&gt;The first step is to reference the coverage analysis assembly,&amp;#160; &lt;em&gt;Microsoft.VisualStudio.Coverage.Analysis.dll&lt;/em&gt;, in your project.&amp;#160; This managed assembly can be found in “%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies” (use %ProgramFiles(x86)% on a 64-bit OS).&amp;#160; The project system should copy the assembly locally for your application to use.&amp;#160; This assembly has native x86 dependencies, so it can only be used from an x86 process.&amp;#160; It is therefore marked as 32-bit required and if you plan on loading it on a 64-bit OS, ensure your entry point assembly is also marked as 32-bit required (i.e. built for the “x86” platform).&lt;/p&gt;  &lt;p&gt;To run your application, you will also need to copy Microsoft.VisualStudio.Coverage.Symbols.dll and dbghelp.dll to your output directory.&amp;#160; These are both native modules, so you won’t be able to add them as a reference.&amp;#160; The easiest way I’ve found to do this is to “Add Existing Item” to the project, browse to the files (both are also in PrivateAssemblies), click the little down arrow next to the “Add” button, select “Add As Link”, select the files in Solution Explorer, bring up the Properties Window, and change “Copy to Output Directory” to “Copy if newer”.&amp;#160; Note that Microsoft.VisualStudio.Coverage.Symbols.dll has a dependency on the Microsoft Debug Interface Access library (msdia100.dll), which is a native COM component that is registered when you install Visual Studio.&amp;#160; You will need to register msdia100.dll using regsvr32.exe on a machine that doesn’t have Visual Studio installed if you plan on using the coverage analysis API.&lt;/p&gt;  &lt;p&gt;Next you’ll want to use the namespace containing the core implementation:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.VisualStudio.Coverage.Analysis;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now that we’ve setup a project to use the analysis API, let’s recall John Cunningham’s old post about &lt;a href="http://blogs.msdn.com/ms_joc/articles/406608.aspx"&gt;using the Visual Studio 2005/2008 coverage analysis API&lt;/a&gt;.&amp;#160; There has been a minor breaking change with the old API.&amp;#160; The &lt;em&gt;CoverageInfoManager&lt;/em&gt; class no longer exists.&amp;#160; Instead, &lt;em&gt;CoverageInfo&lt;/em&gt; objects are created via static methods on &lt;em&gt;CoverageInfo&lt;/em&gt; itself.&amp;#160; Here’s a quick comparison:&lt;/p&gt;

&lt;p&gt;The old way to analyze a file:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; height: 139px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageInfoManager&lt;/font&gt;.ExePath = &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;executable_search_paths&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageInfoManager&lt;/font&gt;.SymPath = &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;symbol_search_paths&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; info = &lt;font color="#2c92af"&gt;CoverageInfoManager&lt;/font&gt;.CreateInfoFromFile(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;path_to_coverage_file&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageDS &lt;/font&gt;dataSet = info.BuildDataSet(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; &lt;font color="#2c92af"&gt;CoverageInfoManager&lt;/font&gt;.Shutdown();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And the new way:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; height: 117px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; info = &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt;.CreateFromFile(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;         &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;path_to_coverage_file&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] { &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;exe_path1&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;exe_path2&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt; }, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] { &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;sym_path1&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;lt;sym_path2&amp;gt;&amp;quot;&lt;/font&gt;&lt;/span&gt; }))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;font color="#2c92af"&gt;CoverageDS&lt;/font&gt; dataSet = info.BuildDataSet();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The executable search paths are locations where the instrumented modules can be found and the symbol search paths are where the instrumented symbols can be found.&amp;#160; They are optional and there is an overload of &lt;em&gt;CoverageInfo&lt;/em&gt;.&lt;em&gt;CreateFromFile&lt;/em&gt; that takes only the path to the coverage file.&amp;#160; The analysis engine will always check the same location as the coverage file to locate the instrumented modules and symbols in addition to the paths supplied. &lt;/p&gt;

&lt;p&gt;The examples above use the &lt;em&gt;CoverageDS&lt;/em&gt; type that is unchanged from Visual Studio 2008.&amp;#160; This type is a typed data set containing the following tables: Module, Namespace, Class, Method, Lines, and SourceFileNames.&amp;#160; It also has methods for exporting/importing the dataset’s data called &lt;em&gt;ExportXml&lt;/em&gt; and &lt;em&gt;ImportXml&lt;/em&gt;.&amp;#160; The exported XML is the same format that Visual Studio uses when it exports a coverage file to XML in the coverage results tool window. &lt;/p&gt;

&lt;p&gt;The downside to using &lt;em&gt;CoverageDS&lt;/em&gt; is that it will load all of the coverage data into memory at the same time.&amp;#160; This is simply not scalable when dealing with large numbers (i.e. many millions) of basic blocks, which usually results in 500 MB or more of data.&amp;#160; Therefore, the Visual Studio 2010 coverage analysis API has an alternative method for enumerating the coverage data on demand.&amp;#160; This also allows for easier filtering before method statistics are rolled up in the statistics of their classes, namespaces, and modules.&lt;/p&gt;

&lt;p&gt;How to dump out the coverage statistics for each method:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt; info = &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt;.CreateFromFile(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;foo.coverage&amp;quot;&lt;/font&gt;&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;font color="#2c92af"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#2c92af"&gt;BlockLineRange&lt;/font&gt;&amp;gt; lines = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;font color="#2c92af"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#2c92af"&gt;BlockLineRange&lt;/font&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;font color="#2c92af"&gt;ICoverageModule&lt;/font&gt; module &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; info.Modules)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] coverageBuffer = module.GetCoverageBuffer(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;font color="#2c92af"&gt;ISymbolReader&lt;/font&gt; reader = module.Symbols.CreateReader())&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; methodId;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; methodName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; undecoratedMethodName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; className;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; namespaceName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;             lines.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (reader.GetNextMethod(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; methodId,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; methodName,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; undecoratedMethodName,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; className,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; namespaceName,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&lt;/span&gt;                 lines))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum25"&gt;  25:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum26"&gt;  26:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;CoverageStatistics&lt;/font&gt; stats = &lt;font color="#2c92af"&gt;CoverageInfo&lt;/font&gt;.GetMethodStatistics(coverageBuffer, lines);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum27"&gt;  27:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum28"&gt;  28:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;Method {0}{1}{2}{3}{4} has:&amp;quot;&lt;/font&gt;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum29"&gt;  29:&lt;/span&gt;                     namespaceName == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ? &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;/span&gt; : namespaceName,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum30"&gt;  30:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(namespaceName) ? &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;/span&gt; : &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;.&amp;quot;&lt;/font&gt;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum31"&gt;  31:&lt;/span&gt;                     className == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ? &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;/span&gt; : className,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum32"&gt;  32:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(className) ? &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;/span&gt; : &lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;.&amp;quot;&lt;/font&gt;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum33"&gt;  33:&lt;/span&gt;                     methodName&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum34"&gt;  34:&lt;/span&gt;                     );&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum35"&gt;  35:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;    {0} blocks covered&amp;quot;&lt;/font&gt;&lt;/span&gt;, stats.BlocksCovered);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum36"&gt;  36:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;    {0} blocks not covered&amp;quot;&lt;/font&gt;&lt;/span&gt;, stats.BlocksNotCovered);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum37"&gt;  37:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;    {0} lines covered&amp;quot;&lt;/font&gt;&lt;/span&gt;, stats.LinesCovered);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum38"&gt;  38:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;    {0} lines partially covered&amp;quot;&lt;/font&gt;&lt;/span&gt;, stats.LinesPartiallyCovered);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum39"&gt;  39:&lt;/span&gt;                 &lt;font color="#2c92af"&gt;Console&lt;/font&gt;.WriteLine(&lt;span style="color: #006080"&gt;&lt;font color="#a41515"&gt;&amp;quot;    {0} lines not covered&amp;quot;&lt;/font&gt;&lt;/span&gt;, stats.LinesNotCovered);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum40"&gt;  40:&lt;/span&gt;                 lines.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum41"&gt;  41:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum42"&gt;  42:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum43"&gt;  43:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum44"&gt;  44:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This example creates a &lt;em&gt;CoverageInfo&lt;/em&gt; in the same manner as above, but instead of calling &lt;em&gt;BuildDataSet&lt;/em&gt;, it enumerates through each module in the coverage file and then enumerates each method in the module to dump out its statistics.&amp;#160; You’ll notice that we call &lt;em&gt;GetCoverageBuffer&lt;/em&gt; on the module which returns a byte[].&amp;#160; There is a byte in this array for each basic block in the module.&amp;#160; If the byte is zero, it means the basic block was not covered.&amp;#160; If it is non-zero, it means the basic block was covered.&amp;#160; So a simple method for counting the “raw” basic blocks covered/not covered would be to count the zero vs. non-zero bytes in this array.&amp;#160; However, the total number of basic blocks reported in coverage statistics is usually less than the total number of basic blocks in the module because certain basic blocks are discarded by &lt;em&gt;GetNextMethod&lt;/em&gt; (usually these basic blocks are for compiler-generated code).&amp;#160; So keep that in mind if you want to analyze the coverage buffer directly.&lt;/p&gt;

&lt;p&gt;Note that each method identifier is unique for a particular build of a module.&amp;#160; Each module has two properties that uniquely identify it: &lt;em&gt;Signature&lt;/em&gt; (a Guid) and &lt;em&gt;SignatureAge&lt;/em&gt; (a uint).&amp;#160; These properties actually correspond go the debug information’s signature information in the module and change whenever a module is re-linked.&amp;#160; For incremental links (VC++), the signature may remain the same while the signature’s age counter will increment, so these two values need to be taken together to version a particular build of a module.&lt;/p&gt;

&lt;p&gt;Also, with modules built by VC++ that were linked with COMDAT folding enabled (an optimization that usually comes into play when using templates), you may see multiple functions returned by &lt;em&gt;GetNextMethod&lt;/em&gt; that map to the same basic blocks because the functions contained duplicate code and were folded into a single copy.&amp;#160; To get around this, we only roll up a method’s statistics to the module’s statistics as long as we haven’t seen the starting basic block before (lines[0].BasicBlockIndex).&amp;#160; That way, the module’s totals are always accurate, although this means you may not always sum up the namespace numbers in a &lt;em&gt;CoverageDS&lt;/em&gt; to arrive at the module’s numbers.&amp;#160; I generally recommend disabling identical COMDAT folding when collecting native code coverage data, as it gives you a better idea of what was actually executed by your tests.&lt;/p&gt;

&lt;p&gt;I’ll leave filtering and doing more complicated analysis (i.e. rollup statistics) as an exercise for the reader.&amp;#160; Hopefully this will serve as a good starting point for those interested in programmatically analyzing code coverage data using Visual Studio 2010. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931021" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Code Coverage" scheme="http://blogs.msdn.com/phuene/archive/tags/Code+Coverage/default.aspx" /><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /></entry><entry><title>Code Coverage in Visual Studio 2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2009/11/30/code-coverage-in-visual-studio-2010.aspx" /><id>http://blogs.msdn.com/phuene/archive/2009/11/30/code-coverage-in-visual-studio-2010.aspx</id><published>2009-12-01T01:00:00Z</published><updated>2009-12-01T01:00:00Z</updated><content type="html">&lt;p&gt;It’s been far, far too long since I’ve updated my blog, but I wanted to quickly cover what’s new in Visual Studio 2010 for code coverage (Premium and higher SKUs).&amp;nbsp; Almost all of the changes are under the covers, but some are noteworthy:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Support for x86-64 instrumentation (native, mixed, and platform-specific managed code) and collection on a 64-bit Windows OS.&amp;nbsp; To utilize this support in VS, set the host platform to “x64” in the test settings.&amp;nbsp; From the command line, use the tools in “%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Team Tools\Performance Tools\x64”.&amp;nbsp; NOTE: the vsperfcmd/vsperfmon you use must match the architecture of the process you’re collecting data from.&amp;nbsp; Hopefully this will be fixed in the future. &lt;/li&gt;    &lt;li&gt;Support for ASP.NET collection in IIS under Vista+ from within Visual Studio.&amp;nbsp; Due to Session 0 Isolation (a security feature of Vista+), code coverage collection was prevented from working within VS.&amp;nbsp; Collection had to be performed manually using the command line tools.&amp;nbsp; In an elevated Visual Studio 2010 instance, Session 0 collection now works correctly. &lt;/li&gt;    &lt;li&gt;Support for concurrent code coverage sessions in Visual Studio 2010 or Team Foundation Build 2010.&amp;nbsp; Previously, code coverage collection was restricted to a single test run in a Windows session, so if multiple test runs were taking place at the same time with code coverage collection enabled, one could possibly fail saying the code coverage monitor was already running.&amp;nbsp; This was occasionally observed in previous versions of Team Foundation Build when a test run had code coverage enabled.&amp;nbsp; Now, each test run’s collection is isolated from one another, so this limitation has been removed. &lt;/li&gt;    &lt;li&gt;Eliminated the common cause of “out of memory” errors from the TFS Coverage Analysis Service (CoverAn) that was responsible for merging code coverage data published against a Team Foundation Build.&amp;nbsp; The service has been replaced with a background job that is capable of efficiently merging very large sets of coverage data.&amp;nbsp; This change also eliminates the requirement that the service identity has to be granted access to the build drop location to perform its work. &lt;/li&gt;    &lt;li&gt;Added the &lt;i&gt;System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute&lt;/i&gt; class to System.dll.&amp;nbsp; This attribute can now be applied to classes, methods, and properties to exclude the collection of code coverage data.&amp;nbsp; Instrumentation still respects the &lt;i&gt;DebuggerNonUserCode &lt;/i&gt;and &lt;i&gt;DebuggerHidden&lt;/i&gt; attributes to prevent instrumentation.&amp;nbsp; However, as these attributes are also used by the debugger when stepping, consider switching to the &lt;i&gt;ExcludeFromCodeCoverage&lt;/i&gt; attribute instead. &lt;/li&gt;    &lt;li&gt;Revamped the analysis API to be more efficient and consistent.&amp;nbsp; I will try to touch on this bullet point in a future blog post describing how to analyze Visual Studio code coverage data programmatically. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Additionally, a bunch of analysis fixes went in to improve the code coverage results and the merging of code coverage files.&amp;nbsp; Unfortunately, the overall code coverage results UI (something I did not own when I owned code coverage) has remained unchanged from the previous version.&lt;/p&gt;  &lt;p&gt;That’s it for now.&amp;nbsp; I hope to blog a little bit more about code coverage before going in-depth into the test impact analysis features of Visual Studio 2010.&amp;nbsp; Following that, I hope to discuss IntelliTrace since that is my current feature area.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9930479" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Code Coverage" scheme="http://blogs.msdn.com/phuene/archive/tags/Code+Coverage/default.aspx" /><category term="Dev10" scheme="http://blogs.msdn.com/phuene/archive/tags/Dev10/default.aspx" /></entry><entry><title>Code Coverage Collection</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2007/05/14/code-coverage-collection.aspx" /><id>http://blogs.msdn.com/phuene/archive/2007/05/14/code-coverage-collection.aspx</id><published>2007-05-14T23:52:37Z</published><updated>2007-05-14T23:52:37Z</updated><content type="html">&lt;p&gt;By&amp;nbsp;the end of my last post about &lt;a href="http://blogs.msdn.com/phuene/archive/2007/05/03/code-coverage-instrumentation.aspx"&gt;code coverage instrumentation&lt;/a&gt;, we have instrumented our executable image and it's now ready for code coverage collection.&amp;nbsp; Code coverage&amp;nbsp;collection is the process of collecting the runtime data of what functions were covered during test execution.&amp;nbsp;&amp;nbsp; The end result of coverage collection will be a coverage data file which can be analyzed to show the coverage results to us in a meaningful way.&lt;/p&gt; &lt;p&gt;Visual Studio uses a&amp;nbsp;separate tool to monitor, coordinate, and flush the coverage data to the coverage file.&amp;nbsp; This tool is VSPerfMon.exe - called the "Visual Studio Performance Monitor" (named so because it was first used by the profiler).&amp;nbsp; When the monitor is started, it listens for incoming connections from executables that have been instrumented for coverage.&amp;nbsp; One of the details I didn't mention about instrumentation is that when an executable image is instrumented, the instrumentation process creates a dependency on VSCover90.dll&amp;nbsp;(9.0 for Orcas, 8.0 for 2005)&amp;nbsp;for the image being instrumented.&amp;nbsp; This is accomplished either though the PE import table for native images or through an injected P/Invoke&amp;nbsp;for managed images.&amp;nbsp; VSCover90.dll is essentially the code coverage runtime and it contains the logic for communicating with the monitor.&amp;nbsp; When VSCover90.dll is loaded and initialized, it will attempt a connection to the monitor.&amp;nbsp; If the monitor is not running, the connection will&amp;nbsp;silently fail and coverage collection will be disabled for the lifetime of the process.&amp;nbsp; An instrumented image will execute normally without the monitor running.&amp;nbsp; If, however, the monitor is running and the connection attempt succeeds, VSCover90.dll will register the hosting process and will begin coverage collection.&lt;/p&gt; &lt;p&gt;VSPerfMon.exe can be found with the other profiler and code coverage tools in "%ProgramFiles%\Microsoft Visual Studio 9.0\Team Tools\Performance Tools".&amp;nbsp; To run the monitor as a foreground process, execute the following command from a command prompt:&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;vsperfmon /coverage /output:&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;path_to_coverage_file&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This will run the monitor in "stand-alone mode".&amp;nbsp; In this mode you can see the processes that have connected to and disconnected from the monitor.&amp;nbsp; The monitor traps Control-C, so to shutdown the monitor you will need to use another tool called VSPerfCmd ("Visual Studio Performance Command").&amp;nbsp; This tool communicates with the running monitor process to perform a variety of tasks.&amp;nbsp; You would execute the following command line to shutdown the monitor:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;vsperfcmd /shutdown&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The command tool can also be used to start the monitor in the background.&amp;nbsp; To do so, execute the following command line:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;vsperfcmd /start:coverage /output:&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;path_to_coverage_file&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This command will cause the monitor to be spawned as a background process.&amp;nbsp; You will use the same command as the one given above to shutdown the monitor.&lt;/p&gt;
&lt;p&gt;There are a few important things to note about the monitor that can prevent successful coverage collection:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;By default, the monitor only accepts connections from processes running under an identity that is a local administrator.&amp;nbsp; The most common problem experienced with this is that no data is collected for ASP.NET web sites.&amp;nbsp; This is due to ASP.NET web sites running under the Network Service identity by default, which is a restrictive identity meant for services that accept network connections.&amp;nbsp; To solve this, there is a /USER switch on VSPerfMon/VSPerfCmd to allow the specified user access to the monitor.&amp;nbsp; When you perform code coverage on a web site inside Visual Studio, a request is made by Visual Studio to discover what the identity of the worker process is.&amp;nbsp; This identity is then passed to the monitor to allow the connection.&amp;nbsp; This happens automatically before test execution when there is a web site checked in the code coverage section of the test run configuration. 
&lt;li&gt;By default, the monitor creates the objects and communication channels needed by the coverage runtime in a local session scope.&amp;nbsp; Therefore, if you are running the monitor in a different session from the process that will connect to the monitor (e.g. if you are not logged on from the console session and you want a service to connect to the monitor), then you need to specify the /CrossSession switch to VsPerfMon/VsPerfCmd.&amp;nbsp; This will instruct the monitor to create those objects in a global scope so that they are accessible from other sessions.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Let's recap what we have so far:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Instrumentation is performed using vsinstr.exe for native, mixed mode, and managed images.&amp;nbsp; To instrument an image, execute the following: "vsinstr.exe /coverage &amp;lt;path_to_image&amp;gt;".&lt;/li&gt;
&lt;li&gt;To start the monitor process that will collect the coverage data, execute the following: "vsperfcmd /start:coverage &amp;lt;path_to_coverage_file&amp;gt;".&lt;/li&gt;
&lt;li&gt;Run the test(s) you want to collect coverage data for using the instrumented images.&lt;/li&gt;
&lt;li&gt;To stop collection, execute the following: "vsperfcmd /shutdown".&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;We now have a coverage file which we can use to view coverage results.&amp;nbsp; The coverage file can be&amp;nbsp;imported into the "Code Coverage Results" tool window inside of Visual Studio.&amp;nbsp; This will show you per-method statistics and double clicking on a method will result in opening the source file in the editor with coverage coloring turned on.&amp;nbsp; I will present a walk-through of how to accomplish everything I've been talking about so far inside of Visual Studio in a future blog entry.&lt;/p&gt;
&lt;p&gt;I will discuss how to use the coverage analysis API to read the coverage file programmatically in&amp;nbsp;my next blog entry.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2632923" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Code Coverage" scheme="http://blogs.msdn.com/phuene/archive/tags/Code+Coverage/default.aspx" /><category term="Collection" scheme="http://blogs.msdn.com/phuene/archive/tags/Collection/default.aspx" /></entry><entry><title>Code Coverage Instrumentation</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2007/05/03/code-coverage-instrumentation.aspx" /><id>http://blogs.msdn.com/phuene/archive/2007/05/03/code-coverage-instrumentation.aspx</id><published>2007-05-04T03:02:00Z</published><updated>2007-05-04T03:02:00Z</updated><content type="html">&lt;p&gt;For my first on-topic blog post, I would like to give an overview of how code coverage instrumentation works in Visual Studio (it seems like a good a place to start as any).&amp;nbsp; For&amp;nbsp;basic information about what code coverage is, check out wikipedia's &lt;a href="http://en.wikipedia.org/wiki/Code_coverage" mce_href="http://en.wikipedia.org/wiki/Code_coverage"&gt;Code Coverage&lt;/a&gt; topic.&amp;nbsp; Code coverage is a feature available in Visual Studio Team Edition for Developers, Visual Studio Team Edition for Testers, and Visual Studio Team Suite.  &lt;/p&gt;&lt;p&gt;One of the most common questions I get by people that know about code coverage is what kind of code coverage does Visual Studio support.&amp;nbsp; Visual Studio uses a block-based statement (also known as C1 coverage) and condition coverage methodology.&amp;nbsp; A block is commonly defined as a sequence of instructions (in this case x86 or CIL instructions) that have a single entry point and a single exit point.&amp;nbsp; We consider an exit point to be a branch instruction, a function call, a return instruction, or, in the case of managed code, a throw instruction.  &lt;/p&gt;&lt;p&gt;I think it'll be useful to to relate this to source code, so take this (rather silly) example in C++:  &lt;/p&gt;&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; foo(&lt;span class="kwrd"&gt;bool&lt;/span&gt; condition)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0;         &lt;span class="rem"&gt;/* block 0 */&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (condition)     &lt;span class="rem"&gt;/* block 0 */&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        i = 5;         &lt;span class="rem"&gt;/* block 1 */&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        i = bar();     &lt;span class="rem"&gt;/* block 2 and 3 */&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; i;          &lt;span class="rem"&gt;/* block 4 */&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Here is the generated debug x86 of the code above (I've replaced the real addresses with easier to read "pseudo-addresses" that erroneously assumes x86 is a one byte fixed-length instruction set):&lt;/p&gt;
&lt;table style="width: 544px; height: 290px;" unselectable="on" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;Address:&lt;/td&gt;
&lt;td valign="top" width="86"&gt;Instruction:&lt;/td&gt;
&lt;td valign="top" width="147"&gt;Operands:&lt;/td&gt;
&lt;td valign="top" width="148"&gt;Block:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="61"&gt;0000&lt;/td&gt;
&lt;td valign="top" width="87"&gt;push&lt;/td&gt;
&lt;td valign="top" width="147"&gt;ebp&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0001&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;ebp,esp&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0002&lt;/td&gt;
&lt;td valign="top" width="87"&gt;push&lt;/td&gt;
&lt;td valign="top" width="147"&gt;ecx&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0003&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;dword ptr [i],0&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0004&lt;/td&gt;
&lt;td valign="top" width="87"&gt;movzx&lt;/td&gt;
&lt;td valign="top" width="147"&gt;eax,byte ptr [condition]&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0005&lt;/td&gt;
&lt;td valign="top" width="87"&gt;test&lt;/td&gt;
&lt;td valign="top" width="147"&gt;eax,eax&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0006&lt;/td&gt;
&lt;td valign="top" width="87"&gt;je&lt;/td&gt;
&lt;td valign="top" width="147"&gt;0009h&lt;/td&gt;
&lt;td valign="top" width="148"&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0007&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;dword ptr [i],5&lt;/td&gt;
&lt;td valign="top" width="148"&gt;1 (due to branch)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0008&lt;/td&gt;
&lt;td valign="top" width="87"&gt;jmp&lt;/td&gt;
&lt;td valign="top" width="147"&gt;000Bh&lt;/td&gt;
&lt;td valign="top" width="148"&gt;1&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;0009&lt;/td&gt;
&lt;td valign="top" width="87"&gt;call&lt;/td&gt;
&lt;td valign="top" width="147"&gt;bar&lt;/td&gt;
&lt;td valign="top" width="148"&gt;2 (due to branch)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;000A&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;dword ptr [i],eax&lt;/td&gt;
&lt;td valign="top" width="148"&gt;3 (due to call)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;000B&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;eax,dword ptr[i]&lt;/td&gt;
&lt;td valign="top" width="148"&gt;4 (multiple entry points)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;000C&lt;/td&gt;
&lt;td valign="top" width="87"&gt;mov&lt;/td&gt;
&lt;td valign="top" width="147"&gt;esp,ebp&lt;/td&gt;
&lt;td valign="top" width="148"&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;000D&lt;/td&gt;
&lt;td valign="top" width="87"&gt;pop&lt;/td&gt;
&lt;td valign="top" width="147"&gt;ebp&lt;/td&gt;
&lt;td valign="top" width="148"&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="62"&gt;000E&lt;/td&gt;
&lt;td valign="top" width="87"&gt;ret&lt;/td&gt;
&lt;td valign="top" width="147"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign="top" width="148"&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Notice that everything up to and including the first branch instruction (je) is considered to be part of the first block.&amp;nbsp; Everything up to and including the next branch instruction (jmp) is part of the second block.&amp;nbsp; The third block is comprised of only the call instruction for the bar function.&amp;nbsp; The fourth block is comprised of storing the return value from the call to bar in the variable i.&amp;nbsp; You'll notice that per the definition of a block as a single entry and single exit sequence of instructions, the instruction at 0x000B has two entry points: as the next instruction from 0x000A and also from the unconditional jump at 0x0008.&amp;nbsp; Therefore, it is also considered the start of a new block and everything up to the final ret instruction is the fifth block.&amp;nbsp; So as you can see, a single line of source code can actually be more than one block.&lt;/p&gt;
&lt;p&gt;The job of instrumentation is to modify the original executable image so that we can detect when blocks are "hit" during execution.&amp;nbsp; To accomplish this, a few instructions (in the case of x86: a push, two movs, and a pop) are inserted before every block to toggle a byte in a buffer&amp;nbsp;that says that the block was executed.&amp;nbsp; You can easily see these instructions by disassembling an instrumented image.&amp;nbsp; Additional information that is required to map a block back to the original source code is also stored in the instrumented image in the form of PE sections.&amp;nbsp; The instrumentation tool relies on debug information to be present to perform the instrumentation.&amp;nbsp; Because the instrumentation process modifies the image, a new debug information database will be written out and referenced from the instrumented executable.&amp;nbsp; By default, the instrumentation tool does an "in-place" instrumentation and overwrites the image being instrumented.&amp;nbsp; The original image is backed up just in case something goes wrong.&amp;nbsp; The instrumented debug information database is actually written out as a different file, so the original debug information database does not need to be backed up.&lt;/p&gt;
&lt;p&gt;The instrumentation tool used by Visual Studio is called vsinstr.exe.&amp;nbsp; This is also the same instrumentation tool used by the profiler to perform trace profiling, however the instrumentation process is quite different than the one used&amp;nbsp;for code&amp;nbsp;coverage.&amp;nbsp; You can find this tool (assuming you're using&amp;nbsp;Orcas) in "%Program Files%\Microsoft Visual Studio 9.0\Team Tools\Performance Tools", which is not actually on the default path for a Visual Studio command prompt.&amp;nbsp; In Orcas, vsinstr.exe supports the instrumentation of native x86, mixed mode x86, and managed images.&amp;nbsp; Unfortunately, 64-bit support did not make it into Orcas, but it is something we would like to get in for a future release.&amp;nbsp; To use vsinstr.exe, simply give it the /coverage switch and the path to the image to instrument:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;vsinstr.exe /coverage foo.dll&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This will generate foo.dll (instrumented), foo.instr.pdb (the instrumented pdb referenced by the instrumented foo.dll), and foo.dll.orig (the backed-up original foo.dll).&amp;nbsp; I will cover exactly how to automatically accomplish the same thing&amp;nbsp;inside of Visual Studio using a screenshot walkthrough in an upcoming blog entry.&lt;/p&gt;
&lt;p&gt;Once an image is instrumented, it is ready for coverage collection, which will be the focus of my next post.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2404081" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author><category term="Code Coverage" scheme="http://blogs.msdn.com/phuene/archive/tags/Code+Coverage/default.aspx" /><category term="Instrumentation" scheme="http://blogs.msdn.com/phuene/archive/tags/Instrumentation/default.aspx" /></entry><entry><title>Welcome to my blog!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/phuene/archive/2007/05/02/welcome-to-my-blog.aspx" /><id>http://blogs.msdn.com/phuene/archive/2007/05/02/welcome-to-my-blog.aspx</id><published>2007-05-02T23:38:00Z</published><updated>2007-05-02T23:38:00Z</updated><content type="html">&lt;p&gt;Hello, my name is Peter and I'm a recovering ex-softie.&amp;nbsp; I returned a few months ago to Microsoft after a little more than two years away from the company.&amp;nbsp; I graduated with a BS in Computer Science from Virginia Tech (I'm also a diehard hokie fan) in 2002.&amp;nbsp; I was a three-time intern before joining Microsoft in as a developer on the Visual C++ project system team.&amp;nbsp; During that time I contributed to Visual&amp;nbsp;C++ 2002, 2003, and 2005.&lt;/p&gt;
&lt;p&gt;I return as a developer on the diagnostics team&amp;nbsp;that is part of&amp;nbsp;Team Developer (Visual Studio Team Edition for Developers), or TeamDev as we like to call it.&amp;nbsp; The diagnostics team owns the debugger, profiler, and code coverage tools within Visual Studio.&amp;nbsp; I am responsible for the code coverage tools and that will be the primary focus of this blog.&amp;nbsp; I will try to also talk about the great things the rest of TeamDev is doing as there are some fantastic things&amp;nbsp;in the works for both Orcas and beyond.&lt;/p&gt;
&lt;p&gt;I am by no means a prolific blogger, but I will try to get some good content sooner than later :).&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2373728" width="1" height="1"&gt;</content><author><name>phuene</name><uri>http://blogs.msdn.com/members/phuene.aspx</uri></author></entry></feed>