locked
How do I get DLL's, from external projects, in my test solution to collect code coverage #'s? RRS feed

  • Question

  • I'm writing a C# based test project that references several DLL's that my development team is producing. I need to be able to use the Code Coverage feature of Visual Studio (Using 2012 RC) to see how well my tests are covering the code in these DLL's. But, no matter how I configure my Test Settings, I can't get the DLL's my test code references to appear in the Code Coverage report...It's only reporting on my test project coverage???

    I've created a Test Settings file based on this link: http://technet.microsoft.com/en-us/query/ms182480

    And, I've configured the Code Coverage section of "Data and Diagnostics" to include the DLL's my code is referencing. But, nothing happens?

    I'm really confused as to when the instrumentation is supposed to happen and how to get the DLL's and their methods to appear in my Code Coverage results???

    Help!


    • Edited by JFamme Monday, June 25, 2012 10:58 PM added info
    Monday, June 25, 2012 10:57 PM

Answers

All replies

  • Hi JFamme

    TestSettings are for VS2010 only.  They can be used in VS 2012 but are really only there for backwards compatibility.  You shouldn't create new ones in 2012.  The reason is that they only support MSTest tests and cannot use the new pluggable test runner architecture.

    This article explains how code coverage works in 2012.

    http://blogs.msdn.com/b/visualstudioalm/archive/2012/06/19/visual-studio-2012-rc-what-s-new-in-code-coverage.aspx

    You will see that CodeCoverage in 2012 " instrument native and managed binaries (DLLs/EXEs) as they are loaded at runtime as long as these binaries are a part of your solution"

    Given that your dll's are not part of your solution you need to customize things slightly.

    There is a new .runsettings file that you can use.  If you go to this blog

    http://blogs.msdn.com/b/sudhakan/archive/2012/05/11/customizing-code-coverage-in-visual-studio-11.aspx

    it runs you through how to create a runsettings file and add it to your solution.  If you make sure that the inclusions section is empty (include all) e.g.

     <Include></Include>

    then it should work fine (I tested your scenario and it worked for me.)


    Please mark as answer if this helps.

    • Marked as answer by JFamme Saturday, June 30, 2012 12:03 AM
    Tuesday, June 26, 2012 12:33 AM
  • I've followed the instructions in the blog...thanks for those. Another question.

    In the Code Coverage results, should the hierarchy be showing the development DLL's that my code is testing, with the percentages that they're being covered by the test project methods...because all I'm seeing is my test project DLL's and it's methods with Code Coverage numbers? I think I'm still missing or misunderstanding something???

    Thanks!

    Wednesday, June 27, 2012 3:16 PM
  • Hi JFamme

    The Code Coverage results should show all of the Dll's and their coverage.  I have attached a picture of my results.

    This shows my unit test project (unittestproject1).  This has a project reference to sut.dll, which in turn has a file reference to account.dll

    Is this not what you see?


    Please mark as answer if this helps.

    Wednesday, June 27, 2012 10:49 PM
  • Hi JFamme

    I blogged about how to set it up here.

    http://scrumdod.blogspot.co.nz/2012/06/visual-studio-2012-code-coverage.html



    Please mark as answer if this helps.

    • Marked as answer by JFamme Saturday, June 30, 2012 12:03 AM
    Thursday, June 28, 2012 3:38 AM
  • Yeah...What you're seeing, is what I "expected" to see, but I haven't seen that yet. But, I'll checkout your blog and keep trying.

    Thanks for your help so far...

    Friday, June 29, 2012 8:41 PM