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
| You must Sign In to use this message board. |
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
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!
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
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?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
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?
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
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'..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Has anyone tried using the regular Java-based CruiseControl to build VStudio projects in stead of CCNET? Is there any real difference here?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|