5,696,576 members and growing! (18,793 online)
Email Password   helpLost your password?
General Programming » Programming Tips » Testing and Quality Assurance     Intermediate License: The Code Project Open License (CPOL)

Integrating Visual Studio Team System 2008 Unit Tests with CruiseControl.NET

By chamindu

Explains how to integrate Visual Studio 2008 unit tests with the CCNET build process
C#, Windows, .NET, Visual Studio (VS2008, Visual Studio), Architect, Dev, QA

Posted: 17 Apr 2008
Updated: 17 Apr 2008
Views: 12,847
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
14 votes for this Article.
Popularity: 5.04 Rating: 4.40 out of 5
0 votes, 0.0%
1
1 vote, 7.1%
2
2 votes, 14.3%
3
1 vote, 7.1%
4
10 votes, 71.4%
5

Introduction

Recently I had to work on a project that used VSTS unit tests and we needed to integrate the tests into our continuous integration process. We were using cruise control.NET. After doing a lot of research on the Web, I decided to write this small article since there is little information on the subject. This article assumes that you have already created a working continuous integration environment with CCNET for your Visual Studio 2008 project.

Executing the Unit Tests

You can use the command line test runner tool MSTest.exe to run your unit tests from CCNET. This requires that you install Visual Studio 2008 on the continuous integration server.

For example, the following command line can be used to execute the unit tests contained in the TestAssembly.dll and store the test results into results.xml.

MSTest.exe /testcontainer:TestAssembly.dll
/resultsfile:results.xml 

One problem with MSTest is that it complains if the results file already exists. To avoid this, you have to delete the results file before calling MSTest. We can create a batch file in the projects working directory to do this, let’s call it RunTests.bat.

del results.xml
MSTest.exe /testcontainer:<PathtoTestProject>\Bin\Debug\TestAssembly.dll
/resultsfile:results.xml

You need to replace <PathToTestProject> with the absolute path of your unit test project and make sure the path to MSTest.exe is added to the system path. Everytime this batch file runs, it will delete the results.xml in the working directory and call MSTest that in turn will run the tests and create a new results file.

Now we need to call this batch file from CCNET. Open your ccnet.config file and insert an exec task just after the msbuild task that builds your project as given below:

<tasks>
    <msbuild>...</msbuild>
    <exec> 
        <executable>{WorkingDirectory}\RunTests.bat</executable>
        <baseDirectory>{WorkingDirectory}</baseDirectory>
    </exec>
</tasks>

Including the Results in the Build Report

First we need to merge the results.xml file to the build log. To do that, update the publishers section of the ccnet.config file as given below:

<publishers> 
    <merge>
    <files>
        <file>{WorkingDirectory}\results.xml</file>
    </files> 
    </merge>
    ... 
</publishers> 

To include the unit test results in the build report, we need XSL files to generate the appropriate HTML. Unfortunately the XSL files supplied with CruiseControl as of version 1.4.0.3172 do not support the output format generated by MSTest version 9. I have created 2 XSL files called MSTest9Report.xsl and MSTest9Summary.xsl that are available in the download. These files are based on the MSTestReport.xsl and MSTestSummary.xsl distributed with CCNET version 1.4.0.3172.

Download and copy the files to the \CruiseControl.NET\server\xsl folder and \CruiseControl.NET\webdashboard\xsl folders. Then modify the ccservice.exe.config (or ccnet.exe.config if you use ccnet.exe instead of the ccservice) file by modifying the xslFiles section as given below:

<xslFiles>
    <file name="xsl\header.xsl"/>
    <file name="xsl\compile.xsl"/>
    <file name="xsl\mstest9summary.xsl"/>
    <file name="xsl\modifications.xsl"/>
</xslFiles>

In the above section, I have removed the unittests.xsl which is there by default and added mstest9summary.xsl instead.

Now we need to configure the Web dashboard. Open the dashboard.config file and update the buildPlugins section as given below:

   <buildPlugins>
      <buildReportBuildPlugin>
        <xslFileNames>
          <xslFile>xsl\header.xsl</xslFile>
          <xslFile>xsl\modifications.xsl</xslFile>
          <xslFile>xsl\compile.xsl</xslFile>
          <xslFile>xsl\MsTest9Summary.xsl</xslFile>
          <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="MSTest Report" actionName="MSTESTReport" 
            xslFileName="xsl\MsTestReport.xsl"/>  

Again, I have removed the unittestsummary.xsl and added mstest9summary instead. The new xslReportBuildPlugin element causes a link to be displayed on the left side called “MSTest Report”, and when clicked it will display the detailed test results in a table.

Conclusion

That's it, now restart your ccservice and your VSTS unit tests should be fully integrated with cruise control. The XSL files supplied displays the Test Name, Outcome, Duration, Message and the Stack Trace but they can be easily modified to display additional information available in the test results.

History

  • 17th April, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

chamindu



Occupation: Software Developer
Location: Sri Lanka Sri Lanka

Other popular Programming Tips articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 27 (Total in Forum: 27) (Refresh)FirstPrevNext
GeneralConfiguring Multiple VSTS Test Projects for Reporting in CruiseControl.NETmemberskingaby13:54 20 Aug '08  
GeneralVery helpfulmemberPaul VR14:58 12 Aug '08  
Questionwill this work for VS2005 as well?memberMJJT14:41 25 Jul '08  
GeneralJust What the Dr. Orderedmemberivolved19:37 14 Jul '08  
GeneralRe: Just What the Dr. Orderedmemberchamindu21:20 14 Jul '08  
RantReference to MsTest9Report.xsl instead of MsTestReport.xsl?memberMilzit18:07 14 Jul '08  
GeneralRe: Reference to MsTest9Report.xsl instead of MsTestReport.xsl?memberchamindu21:20 14 Jul '08  
GeneralRe: Reference to MsTest9Report.xsl instead of MsTestReport.xsl?memberMilzit7:51 15 Jul '08  
GeneralGreat ArticlememberDaniel Fuller19:40 3 Jul '08  
GeneralRe: Great Articlememberchamindu22:30 3 Jul '08  
GeneralGood JobmemberMember 431746720:54 23 Jun '08  
GeneralIssue with running MSTest with CC.NETmemberxxpatanaxx15:06 30 May '08  
GeneralCruiseControl v.s. CruiseControl.NETmemberOrri Eiriksson13:00 14 May '08  
GeneralRe: CruiseControl v.s. CruiseControl.NETmemberntrunnermc11:18 3 Jul '08  
GeneralGreat helpmemberRameshVasu11:50 30 Apr '08  
GeneralRe: Great helpmemberchamindu1:24 15 May '08  
GeneralThanks for that.memberDerek Knight20:46 26 Apr '08  
GeneralRe: Thanks for that.memberchamindu17:58 27 Apr '08  
GeneralAwesome - thanks!memberSteve Michelotti8:47 25 Apr '08  
GeneralRe: Awesome - thanks!memberchamindu17:59 27 Apr '08  
GeneralGood workmembersurangac22:32 24 Apr '08  
NewsConverting VS2008 unit tests to NUnit testsmemberTuomas Hietanen5:28 23 Apr '08  
GeneralRe: Converting VS2008 unit tests to NUnit testsmemberchamindu22:13 24 Apr '08  
QuestionWhat about with a CruiseControl.NET?memberPhilip Ratcliff (Tenet Group)23:26 22 Apr '08  
GeneralRe: What about with a CruiseControl.NET?memberchamindu21:37 23 Apr '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Apr 2008
Editor: Deeksha Shenoy
Copyright 2008 by chamindu
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project