locked
Code coverage metrics for classes in a given file RRS feed

  • Question

  • I have created a set of unit tests in VS 2008. They complete successfully. I also have the code coverage report for the test run. It works fine. I can look at the results for a given namespace and drill down to individual classes and methods.

    However, I would like to see the code coverage totals for all the classes from a particular file (*.cs). In my case, the namespace includes classes in the target file and from other files as well.

    Could anyone suggest a way to filter the results by source file?? Thanks!

    Monday, October 18, 2010 10:31 PM

Answers

  • Thanks for the reply, Tom.

    I am not a fan of multiple classes per file either. However, it is not always an option to re-arrange code just for fun.

    I was hoping to find an easy way to accomplish my code coverage goal. It looks like it is not possible.

    I did write an XSLT to filter down the exported code coverage results. It works and the resulting filtered file can be re-imported into the code coverage viewer. However, the subtotals are in the file at each level and do not get re-computed.

    In the end, the easiest thing to do was to scan the file manually with code coverage coloring turned on.

    Regards,

    Alex

    Wednesday, November 10, 2010 9:16 PM

All replies

  • Hi Alex,

    It is strongly recommended to have each class in a separate file. Most of the time the classes are combined for easy navigation, this is wrong however. If you need better navigation option, try the Resharper add-in. It will allow you to move around much quicker and also provides for easy refactoring (move the classes to separate files) automatically (using a move per class option).

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Tom de Koning Wednesday, November 10, 2010 8:55 PM
    • Unproposed as answer by E. Alex Davis Wednesday, November 10, 2010 8:56 PM
    Wednesday, November 10, 2010 8:51 PM
  • Thanks for the reply, Tom.

    I am not a fan of multiple classes per file either. However, it is not always an option to re-arrange code just for fun.

    I was hoping to find an easy way to accomplish my code coverage goal. It looks like it is not possible.

    I did write an XSLT to filter down the exported code coverage results. It works and the resulting filtered file can be re-imported into the code coverage viewer. However, the subtotals are in the file at each level and do not get re-computed.

    In the end, the easiest thing to do was to scan the file manually with code coverage coloring turned on.

    Regards,

    Alex

    Wednesday, November 10, 2010 9:16 PM