TechnicalArchitectureWorx

The (Unofficial) ITWorx Technical Architecture Blog

MsTest working in CruiseControl.Net

Posted by archworx on June 6, 2007

I’ve trying to get MsTest, the unit tests generated by Visual Studio 2005, to work with cruise control for a while now. So finally I was able to get it to work following these steps below 

Let’s say we have a solution called ITT in the following path c:/ITT, first we’ll look at the ccnet config file, after you compile using the msbuild task, you have to call an exec task to execute the MsTests, but before that you have to delete the test results file because MsTest won’t run if the file is already there, we are doing this by calling a batch file to delete this test results file and also delete the temp folders created by MsTest. After that you have to merge the results file with build output so I can be displayed in the dashbaord.

 <project name=”ITT”>
    <webURL>http://localhost/ccnet</webURL&gt;
    <triggers>
      <intervalTrigger seconds=”100″ />
    </triggers>
    <modificationDelaySeconds>120</modificationDelaySeconds>

    <!– here you do the task to get the project from the source control –>
    <!–sourcecontrol type=”vss” autoGetSource=”true” applyLabel=”false”>
    </sourcecontrol–>

    <tasks>
      <!– task to build the solution–> 
      <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
        <workingDirectory>c:\ITT</workingDirectory>
        <projectFile>ITT.sln</projectFile>
        <targets>Build</targets>
        <timeout>60</timeout>
        <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
      </msbuild>

      <exec>
        <!– call a batch file that deletes results.trx –>
        <!– this is required as MsTest will not create the file if it exists–>
        <!– the batch file also deletes the temp folders created by MsTest –> 
        <executable>delTestLog.bat</executable>
        <baseDirectory>c:\ITT</baseDirectory>
        <buildArgs></buildArgs>
        <buildTimeoutSeconds>30</buildTimeoutSeconds>
      </exec>
     
      <exec>
        <!– the exec task to execute the MsTest task –>
        <executable>C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\MSTest.exe</executable>
        <baseDirectory>c:\ITT</baseDirectory>
        <buildArgs>/testcontainer:\ITT\AnalysisLibTests\bin\Debug\AnalysisLibTests.dll /runconfig:localtestrun.testrunconfig /resultsfile:results.trx</buildArgs>
        <buildTimeoutSeconds>600</buildTimeoutSeconds>
      </exec>

    </tasks>
    <publishers>
      <!–to get the test results in the dashboard we have to merge the results XML file –>
      <merge>
        <files>
          <file>c:\ITT\results.trx</file>
        </files>
      </merge>
      <xmllogger />
      <email from=”CruiseControl” mailhost=”mail” includeDetails=”TRUE”>

      </email>
    </publishers>
</project>

The next step is to modify the dashboard config file to display the test results, first we update the dashboard.config file to include the MsTests details menu item and then we add the MsTest results summary to the main build page. The required xsl files are already included with ccnet, you can customize the xsl to fit your needs

<buildReportBuildPlugin>
  <xslFileNames>
    <xslFile>xsl\header.xsl</xslFile>
    <xslFile>xsl\modifications.xsl</xslFile>
    <xslFile>xsl\compile.xsl</xslFile>
    <xslFile>xsl\MsTestSummary.xsl</xslFile> <!– MsTest results summary in main page–>
    <xslFile>xsl\unittests.xsl</xslFile> <!– Nunit test results, can be removed if not required any more –>
    <xslFile>xsl\fxcop-summary.xsl</xslFile>
    <xslFile>xsl\NCoverSummary.xsl</xslFile>
    <xslFile>xsl\SimianSummary.xsl</xslFile>
    <xslFile>xsl\fitnesse.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=”MSTest Report” actionName=”MSTESTReport” xslFileName=”xsl\MsTestReport.xsl”/> <!– menu item –>
   <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”/> 

 That’s all

Advertisements

3 Responses to “MsTest working in CruiseControl.Net”

  1. Miguel said

    Hi,

    Thanks foy rour post. It was really a help for me.

    Have you ever tried to use MSTest of Visual Studio 2008. It seems that the xml generated in the test report is very different from the VS2005 version, and consequently the mstestsummary.xsl doesn’t show any results.

    I’ve tried to change the mstestsummary.xsl file, and i can now see the results. But my skills in xsl are not the best ones. Do you know if there is a XSL file for Visual Studio 2008 Test report?

    I’ve changed a few lines and i can now see the summary result.

    It will be very nice, if someone publish the xsl for visual studio 2008.

    Just my 2 cents.

    Miguel

  2. Asier said

    Miguel,

    Have a look on this page: http://www.codeproject.com/KB/tips/VSTS2008_Tests_With_CCNET.aspx

    Chamindu has written the xsl files for visual studio 2008.

    Asier

  3. apple said

    apple…

    […]MsTest working in CruiseControl.Net « TechnicalArchitectureWorx[…]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: