Click here to Skip to main content
Email Password   helpLost your password?

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralGood
AlanLiuhua
23:28 10 Feb '10  
Thank you.
GeneralTop Article!
KazMaxLtd
3:59 8 Jan '10  
I've been using Visual Studio and CruiseControl with Nant for a while, but never got around to adding tests to the build process. This morning I implemented a few dozen tests, and then set about adding the tests to my build process on my build server.

A quick google brought up a link to this article, which I have followed as instructed, and a couple of hours later my build system has testing enabled.

Top work, well done for sharing.

Andrew
Generalvery good
Donsw
17:39 3 May '09  
Its great to be able to add this to cc.

cheers,
Donsw
My Recent Article : Ajax Calendar Control

QuestionVery Cool
novocaine
13:39 16 Apr '09  
Nice article. I was able to get everything up and running very quickly thanks for that. I have MSTest running several different test suites for a project and so I wrote a small program that executes for ccnet.config and replaces the UnitTestRun tags with a more specific tag for that test suite (like IntegrationTestRun, AcceptanceTestRun, etc)in my results.xml file. Then I have xslt files for each test run type and I can view different reports for each type. This works well however I did have a question about the xsl files that you provided, I'm a relative newbie to xsl and have never seen the tt: syntax that you use when referencing node names. Is this X-Path or something else? I was not able to turn anything up on google. Thanks in advance.
GeneralIssue with CruiseControl WebDashboard
jaanuforabdi
4:12 30 Dec '08  
Hi,

After merging the files of VS Test I am unable to display the result on Web Dashboard of cruisecontrol.net.

I have included the latest .xsl files in both xsl folders(\\server and \\WebDashboard).The files are MsTest9Report.xsl and MsTest9Summary.xsl

Also on modifying the dashboard config file to display the MS Test link,there is no change in the appearance of web dashboard.I am really screwed up and trying to find out a solution to this issue.

Can anyone please give an input??

Thanks,

Abdi.
GeneralConfiguring Multiple VSTS Test Projects for Reporting in CruiseControl.NET
skingaby
13:54 20 Aug '08  
I have several Projects in my Solution. Each Project has its own Test Project.
In order to handle this, I changed the RunTests.bat file to write one results file for each *.Test.dll:

RunTests.bat
del artifacts\results*.xml
MSTest.exe /testcontainer:<PathtoTestProject>\Bin\Debug\Assembly.One.Test.dll /resultsfile:artifacts\resultsOne.xml
MSTest.exe /testcontainer:\Bin\Debug\Assembly.Two.Test.dll /resultsfile:artifacts\resultsTwo.xml

The publishers section of the ccnet.config is changed to merge both files:

ccnet.config
<publishers>
<merge> <files> <file>artifacts\resultsOne.xml</file> <file>artifacts\resultsTwo.xml</file> </files> </merge> ...
</publishers>

And I changed the XSL in the stylesheet from:

BEFORE
MsTest9Summary.xsl, MsTest9Report.xsl
<xsl:template match="/"> <xsl:variable name="pass_count" select="cruisecontrol/build/tt:TestRun/tt:ResultSummary/tt:Counters/@passed"/> <xsl:variable name="inconclusive_count" select="cruisecontrol/build/tt:TestRun/tt:ResultSummary/tt:Counters/@inconclusive"/> <xsl:variable name="failed_count" select="cruisecontrol/build/tt:TestRun/tt:ResultSummary/tt:Counters/@failed"/> <xsl:variable name="total_count" select="cruisecontrol/build/tt:TestRun/tt:ResultSummary/tt:Counters/@total"/>

to:

AFTER
MsTest9Summary.xsl, MsTest9Report.xsl
<xsl:template match="cruisecontrol"> <xsl:for-each select="build"> <xsl:apply-templates select="tt:TestRun"/> </xsl:for-each> </xsl:template> <xsl:template match="tt:TestRun"> <xsl:variable name="pass_count" select="tt:ResultSummary/tt:Counters/@passed"/> <xsl:variable name="inconclusive_count" select="tt:ResultSummary/tt:Counters/@inconclusive"/> <xsl:variable name="failed_count" select="tt:ResultSummary/tt:Counters/@failed"/> <xsl:variable name="total_count" select="tt:ResultSummary/tt:Counters/@total"/> ...
Change any other references from "cruisecontrol/build/tt:TestRun/..." to "..."

Thanks to Chamindu for this excellent article and for the XSL files I needed!
GeneralRe: Configuring Multiple VSTS Test Projects for Reporting in CruiseControl.NET
bflecht
5:24 23 Feb '09  
This works for the most part for me. I'm having a problem, though. Let's say I had two test projects each with a test method. If one fails and one passes, Cruise Control still says my build has passed. The summary and report show properly, but for some reason CC doesn't know what has happened. If both tests fails then it properly flags the build as failed. Any ideas?
GeneralRe: Configuring Multiple VSTS Test Projects for Reporting in CruiseControl.NET
KazMaxLtd
1:31 9 Jan '10  
I wondered whether you had found a solution to this situation where one of the tests fails, but others pass?

I have just implemented the functionality documented in this article and got everything working. Except that I have 49 tests - 48 of them pass but one fails. And CruiseControl.net reports that the build was successful. Have been pulling my hair out trying to figure out why.

Andrew
GeneralRe: Configuring Multiple VSTS Test Projects for Reporting in CruiseControl.NET
KazMaxLtd
1:44 9 Jan '10  
Okay, sorted. The following article advises to add a line to the batch file:

http://www.mail-archive.com/ccnet-user@googlegroups.com/msg03027.html

The line which needs to be added to the batch file after MSTest is:

if not %errorlevel% == 0 exit 1

That seems to do the trick!

Andrew
GeneralVery helpful
Paul VR
14:58 12 Aug '08  
You saved me a bunch of time. Thanks man,

Paul
Questionwill this work for VS2005 as well?
MJJT
14:41 25 Jul '08  
we have to use VS2005 for the new project that we are working on and I am just wondering if your templates and the process you described will work for 2005 as well? thank you.
GeneralJust What the Dr. Ordered
ivolved
19:37 14 Jul '08  
I was not looking forward to writing my own XSL to get this working properly...thanks you saved me an hour or so...for that alone 5 stars!
GeneralRe: Just What the Dr. Ordered
chamindu
21:20 14 Jul '08  
You are welcome
RantReference to MsTest9Report.xsl instead of MsTestReport.xsl?
Milzit
18:07 14 Jul '08  
Thank you. But should you not make a reference to MsTest9Report.xls in the xslReportBuildPlugin and not MSTestReport.xsl as you have written? (As you keep the existing xls files) Following your article I just get an empty test result html-page as before with the old xls files.
GeneralRe: Reference to MsTest9Report.xsl instead of MsTestReport.xsl?
chamindu
21:20 14 Jul '08  
You are correct, thanks for pointing it out.
GeneralRe: Reference to MsTest9Report.xsl instead of MsTestReport.xsl?
Milzit
7:51 15 Jul '08  
I have changed the line to :
<xslReportBuildPlugin description="MSTest Report" actionName="MSTESTReport" xslFileName="xsl\MsTest9Summary.xsl"/>
When a build is failing I get a nice formated view of the test that have failed. But when I press the MSTestReport link of a green build, I just get the text "All test passed"
Should I not get the info here with the green formatering, info on run time for each test etc?
GeneralGreat Article
Daniel Fuller
19:40 3 Jul '08  
Thanks for this, saved me a lot of time fiddling around!
GeneralRe: Great Article
chamindu
22:30 3 Jul '08  
You are welcome
GeneralGood Job
Member 4317467
20:54 23 Jun '08  
Thanks
GeneralIssue with running MSTest with CC.NET
xxpatanaxx
15:06 30 May '08  
I'm having problem when running my batch file using CC.NET and my unit tests don't pass but when I run the same batch file using windows command line, it runs fine.
Does anyone know what might be causing this?
The error I'm getting when I run my unit test using CC.NET is the following:
Unit Test Adapter threw exception: Type is not resolved for member [class name1],[project name1], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'..
GeneralCruiseControl v.s. CruiseControl.NET
Orri Eiriksson
13:00 14 May '08  
Has anyone tried using the regular Java-based CruiseControl to build VStudio projects in stead of CCNET? Is there any real difference here?
GeneralRe: CruiseControl v.s. CruiseControl.NET
ntrunnermc
11:18 3 Jul '08  
I have done it. I use ANT as my build tool and just build the solution using the command-line option. Of course, VStudio must be installed on the build machine which also means that you must be on a Windows machine.

The first target builds with 2005

<target name="build.crownpeak.dll.2005" depends="copy_DLL_Src, customStrip">
<exec executable="${devenv.path}/devenv" failonerror="true">
<arg value="${build_dir}/DLL_Src/com.vs.2005/CrownPeak/CrownPeak.sln"/>
<arg value="/Rebuild"/>
<arg value="Debug"/>
</exec>
</target>

This one is for VS 98
<target name="build.crownpeak.dll.98" depends="copy_DLL_Src, customStrip">
<exec executable="${msdev.path}/msdev" failonerror="true">
<arg value="${build_dir}/DLL_Src/com/CrownPeak/CrownPeak.dsw"/>
<arg value="/Make"/>
<arg value="CrownPeak - Win32 Debug"/>
<arg value="/REBUILD"/>
</exec>
</target>
GeneralGreat help
RameshVasu
11:50 30 Apr '08  
Your article was very helpful. Before I came across this article, I spent a lot of time trying to make sense of information from different sites. You have pulled it all together very well and have included the new XSL file. Thanks. Cool
GeneralRe: Great help
chamindu
1:24 15 May '08  
You are welcome. Nice to know that it helped you
GeneralThanks for that.
Derek Knight
20:46 26 Apr '08  
I spotted one small mistake but fixed that myself:

In the dashboard config, you should have had xslFileName="xsl\MsTest9Report.xsl", but you'd missed the '9' out so the wrong XSL file was being used, which resulted in a blank report.

Great work though and thanks a lot
Derek


Last Updated 17 Apr 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010