views:

162

answers:

1

Does anyone know of a tool that will spit out a list of all methods with the [TestMethod] attribute within a solution?

What we're trying to accomplish is a review, with the customer, of our Unit Tests (names, not pass/fail status) against the Requirements. We are using VSTS 2008 and Scrum for Team Systems, so I wasn't sure if this was something that was built in somewhere, or if it's a tool I just need to toss together for our purposes. Any help would be great. Thanks.

+1  A: 

VS essentially offers this ability for free by generating the TRX file to summarize the results of a test run. There are a number of different ways to run all tests in a project but pick one and off mstest will go running each method with the [TestMethod] attribute and producing a UnitTestResult in the results file.

What you're asking for is essentially what the Test Results window shows you after a completed Test Run. If you're looking for something external to VS, you could always run a simple XSLT transform against the Test Results (.trx) file giving you a customized summary. Here's a very rough sample which proofs the concept, generating an HTML document containing an unordered list with a list item (test name and result) for each unit test:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:vs="http://microsoft.com/schemas/VisualStudio/TeamTest/2006"&gt;

 <xsl:template match="/">
  <html>
   <head>
    <style type="text/css">

     body { font-family: verdana; font-size: 12px; }

     .pass { color: green; }
     .nopass { color: red; }

     h1 { font-size: 13px; margin: 3px; }

     ul { margin: 3px 20px 3px 40px; }
    </style>
   </head>
   <body>

    <h1>Test Results</h1>
    <ul>

   <xsl:apply-templates select="//vs:Results//vs:UnitTestResult" />

    </ul>
   </body>
  </html>

 </xsl:template>
 <xsl:template match="vs:UnitTestResult" >
  <li>
   <xsl:value-of select="@testName" />
   &#160;

   <xsl:variable name="Result">
    <xsl:choose>
     <xsl:when test="@outcome='Passed'">pass</xsl:when>
     <xsl:otherwise>nopass</xsl:otherwise>
    </xsl:choose>
   </xsl:variable>

   <b class="{$Result}">
    <xsl:value-of select="@outcome" />
   </b>
  </li>

 </xsl:template>
</xsl:stylesheet>
John