Chris's profileChris Burrows' Live Spac...PhotosBlogListsMore Tools Help

Blog


    September 22

    Code Coverage, Web Application Project

    One of the challanges that I have been having lately was getting code coverage working on our build machine.  I was able to get code coverage working for normal dll's but I couldn't get it working for Web Application projects.    The old saying "it worked on my machine" held true in this case.    I could get the code coverage working for the Web application project, but I couldn't get it working on my machine.   After scratching my head for a while, I thought to myself where is the code for the web site getting executed when you just tests against the web site.    After having a look on the build machine, I had a hunch that it might be in the _PublishedWebSites directory.   So I added a quick bit of code to the web application project to write out it's location to the event log and it confirmed my hunch.   (For those of you who are unsure where the _PublishedWebSite directory is found it is in <BuildDirectory>\<TeamProjectName>\<BuildTypeName>\Binaries\<Configuration>\_PublishedWebSites.  On my build machine that is d:\build\TestTeamProject\TestContinuous\Release\_PublishWebSites.    

    So how did I solve the problem.   What I did was open up the solution file on the build machine underneath the  <BuildDirectory>\<TeamProjectName>\<BuildTypeName>\Source directory.   I then openned up the .testrunconfig file (See Enabling Code Coverage) and added the assemblies that I wanted to enable code coverage for and I suddenly had code coverage results.

     

    For those who don't have access to the build machine, you can achieve the same thing by editing the .testrunconfig file manually.    Instead of double clicking on the .testrunconfig file, right mouse click and selected open with.  This will bring up the following dialogue. 

    Select the XML Editor.  This will bring up an XML editor from which you can manual edit the file.   The section that you are looking for is below:

     

    <isCodeCoverageEnabled type="System.Boolean">True</isCodeCoverageEnabled>
        <codeCoverageItems type="System.Collections.Generic.List`1[[Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]">
         <_items type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem[]">
            <element type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem">
             <binaryFile type="System.String">bin\Debug\UpdateWarehouse.exe</binaryFile>
             <keyFile type="System.String" />
             <pdbFile type="System.String">obj\Debug\UpdateWarehouse.pdb</pdbFile>
             <instrumentInPlace type="System.Boolean">True</instrumentInPlace>
             <outputDirectory type="System.String" />
            </element>
         </_items>
         <_size type="System.Int32">1</_size>
         <_version type="System.Int32">1</_version>
        </codeCoverageItems>

    All that you need to do is add in one of the elements and update the _size and _version with the number of elements in the collection array.      A tip that I discovered.  Normally when you open the .testrunconfig file as an XML document all you see if one long string.   If you do CTRL+A then CTRL+F (That is select all then Edit.FormatDocument). 

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://madtechnology.spaces.live.com/blog/cns!F637E4FD356E127D!138.trak
    Weblogs that reference this entry
    • None