BM Bloggers

The blog of the Black Marble development team
MSTest and CruiseControl .NET

I have been trying to get Visual Studio 2005 Team Developer style unit tests working within CruiseControl.

The documention says it should work, but is a little scant as to the detail of how to do it. So now I have it all going I thought an example of the working ccnet.config file with some comments might help other people trying to get this going.

So the background is I have a VS.NET 2005 solution (My Sample.sln) with some projects in it. One of these is a Test Project (TestProject.csproj). This contains some test which can be run via the Test menu option is VS.NET.

CCNET.CONFIG

<project name="My Sample">
<!--Here you put any other project level settings-->
<!--the working directory is used for all relative file references-->

<workingDirectory>C:\projects\My Sample</workingDirectory>

<!--Normally you would have all your source control bits here-->

<tasks>
    <!--We use the Visual Studio build model, you could also use the MSBUILD-->
   
<
devenv>
            <
solutionfile>"C:\projects\My Sample\My Sample.sln"</solutionfile>
            <
configuration>Debug</configuration>
            <
buildtype>Build</buildtype>
            <!--Comment out the project block so it build the whole solution-->
            <!--
<project>MyProject</project>-->
            <
executable>"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.com"</executable>
            <
buildTimeoutSeconds>90</buildTimeoutSeconds>
     </
devenv>

     <exec>
            <!--Call a batch file that contains del testResults.trx -->
            <!--this is required as MsTest will not create the file if it exists-->
            <!--this could be merged with the mstext action in a single batch file-->
            <
executable>deleteTestLog.bat</executable>
            <
baseDirectory>C:\projects\My Sample</baseDirectory>
            <
buildArgs></buildArgs>
            <
buildTimeoutSeconds>30</buildTimeoutSeconds>
      </
exec>

      <exec>
            <!--Call mstest to run the tests contained in the TestProject -->
            <
executable>C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\mstest.exe</executable>
            <
baseDirectory>C:\projects\My Sample</baseDirectory>
            <!--testcontainer: points to the DLL that contains the tests -->
            <!--runconfig: points to solutions testrunconfig that is created by vs.net, list what test to run -->
            <!--resultsfile: normally the test run log is written to the uniquely named testresults directory  -->
            <!--                   this option causes a fixed name copy of the file to be written as well -->
            <
buildArgs>/testcontainer:testproject\bin\debug\testproject.dll /runconfig:localtestrun.Testrunconfig /resultsfile:testResults.trx</buildArgs>
            <
buildTimeoutSeconds>30</buildTimeoutSeconds>
      </
exec>

</tasks>

<publishers>
         <!--to get the test results in the dashboard we have to merge the results XML file -->
         <!--the project working directory is used as the base path here -->
         <
merge>
               <
files>
                     <
file>testResults.trx</file>
               </
files>
         
</merge>
         <!--this is the line I missed for ages, without it you get strange missing publisher log errors -->
         <
xmllogger />
</
publishers>

</project>
</
cruisecontrol>

DASHBOARD.CONFIG

By default with CCNET build 1277 has the entry to display MSTest results in the summary. If you want the results on a separate menu item (like nUnit or FxCop) then the dashboard.config should contain the following bits

<buildPlugins>
<
buildReportBuildPlugin>
<
xslFileNames>
<!--all these xsl entries are in the 1277 build -->
   <
xslFile>xsl\header.xsl</xslFile>
   <
xslFile>xsl\modifications.xsl</xslFile>
   <
xslFile>xsl\compile.xsl</xslFile>
   <
xslFile>xsl\unittests.xsl</xslFile>   
   <
xslFile>xsl\MsTestSummary.xsl</xslFile>
   <
xslFile>xsl\fxcop-summary.xsl</xslFile>
   <
xslFile>xsl\NCoverSummary.xsl</xslFile>
   <
xslFile>xsl\SimianSummary.xsl</xslFile>
</
xslFileNames>
</
buildReportBuildPlugin>

<buildLogBuildPlugin />
   <
xslReportBuildPlugin description="NUnit Details" actionName="NUnitDetailsBuildReport" xslFileName="xsl\tests.xsl" />
   <
xslReportBuildPlugin description="NUnit Timings" actionName="NUnitTimingsBuildReport" xslFileName="xsl\timing.xsl" />
   <
xslReportBuildPlugin description="NAnt Output" actionName="NAntOutputBuildReport" xslFileName="xsl\Nant.xsl" />
   <
xslReportBuildPlugin description="NAnt Timings" actionName="NAntTimingsBuildReport" xslFileName="xsl\NantTiming.xsl" />
   <
xslReportBuildPlugin description="FxCop Report" actionName="FxCopBuildReport" xslFileName="xsl\FxCopReport.xsl" />
   <
xslReportBuildPlugin description="NCover Report" actionName="NCoverBuildReport" xslFileName="xsl\NCover.xsl" />
   <
xslReportBuildPlugin description="Simian Report" actionName="SimianBuildReport" xslFileName="xsl\SimianReport.xsl"/>
   <!--add the following line to add the extra menu item-->
   <
xslReportBuildPlugin description="MSTest Report" actionName="MSTESTReport" xslFileName="xsl\MsTestSummary.xsl"/>
</buildPlugins>

Published 14 June 2006 22:29 by Richard

Filed under:

Comments

No Comments