Displayin StatLight Unit Test Results in CruiseControl.Net Web Dashboard

Nov 4, 2010 at 8:46 AM
Edited Nov 4, 2010 at 8:56 AM

I've managed to get StatLight working great in CruiseControl.Net to automatically run our SilverLight Unit tests and output a report using the -r flag.

But I was wondering if there is a way to display the unit test results report in the ccnet dashboard (web dashboard) like you can with Nunit tests?

Here are my ccnet.config  and dashboard.config files:

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
 <project name="iLaboratory Silverlight">
  <artifactDirectory>E:\Builds\Artifacts\iLaboratory Build</artifactDirectory>
  <workingDirectory>E:\Development\NextGen\trunk\iLaboratory\</workingDirectory>
  <triggers>
    <intervalTrigger seconds="600" />
  </triggers>
  <sourcecontrol type="svn">
    <executable>
        C:\Program Files\SlikSvn\bin\svn.exe
    </executable>
    <workingDirectory>
        E:\Development\NextGen\trunk\iLaboratory
    </workingDirectory>
    <trunkUrl>
        http://mysvnserver/svn/lab-products/NextGen/trunk
    </trunkUrl>
    <autoGetSource>true</autoGetSource>
    <username>myuser</username>
    <password></password>
   </sourcecontrol>
   <tasks>
     <msbuild>
       <executable>
        C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
       </executable>
       <workingDirectory>
        E:\Development\NextGen\trunk\iLaboratory
       </workingDirectory>
       <projectFile>iLaboratory.sln</projectFile>
       <buildArgs>
        /noconsolelogger /p:Configuration=Debug
       </buildArgs>
       <targets></targets>
       <timeout>300</timeout>
       <logger>
        C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll
       </logger>
     </msbuild>
     <exec>
       <buildArgs>-x="E:\Development\NextGen\trunk\iLaboratory\UnitTests\SilverlightUnitTests\Bin\Debug\SilverlightUnitTests.xap" -r="E:\Builds\Artifacts\iLaboratory Build\SilverLightUnitTest-results.xml"</buildArgs>
       <buildTimeoutSeconds>5000</buildTimeoutSeconds>
       <baseDirectory />
       <description />
       <environment />
       <executable>E:\Program Files\StatLight\StatLight.exe</executable>
     </exec>
   </tasks>
  <!--Publishers will be done after the build has completed-->
   <publishers>
  
    <exec>
      <buildArgs>"E:\Builds\Artifacts\iLaboratory Build\SilverLightUnitTest-results.xml" /r:ModuleSummary /xml /m:95 /f</buildArgs>
      <buildTimeoutSeconds>5000</buildTimeoutSeconds>
      <baseDirectory>E:\Builds\Artifacts\iLaboratory Build</baseDirectory>
      <description />
      <environment />
      <executable>C:\Program Files\TestDriven.NET 3\NCoverExplorer\NCoverExplorer.Console.exe</executable>
    </exec>
  
    <merge>
      <description />
      <files>
        <file>E:\Builds\Artifacts\iLaboratory Build\*.xml</file>
      </files>
    </merge>
    <xmllogger logDir="E:\Builds\Artifacts\iLaboratory Build\buildlogs" />
     <statistics>
      <statisticList />
    </statistics>
      </publishers>
  <queue>NextGenQueue</queue>
  <queuePriority>30</queuePriority>
  <modificationDelaySeconds>10</modificationDelaySeconds>
 </project>

</cruisecontrol>

dashboard.config file:

<?xml version="1.0" encoding="utf-8"?>
<dashboard>
  <remoteServices>
    <servers>
      <!-- Update this list to include all the servers you want to connect to. NB - each server name must be unique -->
      <server name="local" url="tcp://localhost:21234/CruiseManager.rem" allowForceBuild="true" allowStartStopBuild="true" backwardsCompatible="false" />
    </servers>
  </remoteServices>
  <plugins>
    <farmPlugins>
      <farmReportFarmPlugin />
      <cctrayDownloadPlugin />
      <administrationPlugin password="" />
    </farmPlugins>
    <serverPlugins>
      <serverReportServerPlugin />
    </serverPlugins>
    <projectPlugins>
      <projectReportProjectPlugin />
      <viewProjectStatusPlugin />
      <latestBuildReportProjectPlugin />
      <viewAllBuildsProjectPlugin />
    </projectPlugins>
    <buildPlugins>
      <buildReportBuildPlugin>
        <xslFileNames>
          <xslFile>xsl\header.xsl</xslFile>
          <xslFile>xsl\modifications.xsl</xslFile>
          <xslFile>xsl\MsTestSummary2008.xsl</xslFile>
          <xslFile>xsl\unittests.xsl</xslFile>
        </xslFileNames>
      </buildReportBuildPlugin>
      <xslReportBuildPlugin description="MSTest Report" actionName="MSTESTReport" xslFileName="xsl\MsTestSummary2008.xsl"/>
      <buildLogBuildPlugin />
    </buildPlugins>
    <securityPlugins>
      <simpleSecurity />
    </securityPlugins>
  </plugins>
</dashboard>

Thanks in advance.

B.

Coordinator
Nov 4, 2010 at 1:28 PM

As of now, I don't have CC.Net installed anywhere (which is why I haven't built better support for StatLight in cc.net). However, I had a someone post something he had working a while back as a patch that I just never got around to integrating. http://statlight.codeplex.com/SourceControl/PatchList.aspx.

Since the original patch was submitted, the StatLight xml report format has changed significantly. So I'm sure the xslt in there won't work right away, but it would be interesting to see if you could modify it to work and if possible post back here anything you get working. I would like to support cc.net better, just haven't taken the time to get the server setup.

Hope this helps.

Nov 4, 2010 at 1:58 PM

Okay I understand now what I need to do, basically I need to write some xslt to convert the StatLight reoprt output xml to html and then plug that xslt into ccnet dashboard config so it can then convert and display it.

I'll post the xslt and ccnet config once I have done it.

Thanks for your help.

B.

Nov 4, 2010 at 4:58 PM
Edited Nov 4, 2010 at 4:59 PM

Okay managed to get this working a treat!

 Below is the xsl template I use to convert the xml to html so ccnet dashboard can display the StatLight xml report results:

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="html"/>
 <xsl:template match="/">
   <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='StatLightTestResults']" />
 </xsl:template>
 <xsl:template match="/cruisecontrol/build/*[local-name()='StatLightTestResults']">

    <html>
       <head>
         <title>Silverlight Test Results</title>
       </head>
       <body>
        <h1>Silverlight/StatLight Test Results</h1>
         <p><b>Total tests run = <xsl:apply-templates select="@total" /> Total tests ignored = <xsl:apply-templates select="@ignored" />
          Total tests failed  = <xsl:apply-templates select="@failed" />
          Test run date = <xsl:apply-templates select="@dateRun" /></b>
         </p>
         <xsl:for-each select="tests">
              <table border="2">
              <tr>
              <th>Test Name</th>
              <th>Result</th>
              <th>Time to complete</th>
              </tr>
              <xsl:for-each select="test">
 		<tr>
                  <td><xsl:apply-templates select="@name" /></td>
                  <td><xsl:apply-templates select="@resulttype" /></td>
                  <td><xsl:apply-templates select="@timeToComplete" /></td>
                 </tr>
              </xsl:for-each>
          </table>
         </xsl:for-each>
       </body>
     </html>  

  </xsl:template>

</xsl:stylesheet>

The above xsl template needs to be put in the ccnet webdashboard\xsl folder, which in my case is C:\Program Files\CruiseControl.NET\webdashboard\xsl

Add the following line to the dashboard.config (note the  xslFileName must match the name of your xsl file you create):

<xslReportBuildPlugin description="Silverlight Test Report" actionName="SLTestReport" xslFileName="xsl\SilverLightStatLightTest.xslt"></xslReportBuildPlugin>

Restart IIS where the ccnet dashboard is running and you should see a Silverlight Test Report option under each build, click that and a simple table with all the results are displayed.

You can of course tweak the xsl above to make the html output fancier if you wish but I have kept it simple so people can follow it.

All this is based on the ccnet.config file posted here and the dashboard.config file with the addtional xslReportBuildPlugin

 

 

Coordinator
Nov 5, 2010 at 3:56 PM

Thanks for doing this... When I get some time, I'd like to play with what you did, and even include it into the StatLight documentation.

Nov 5, 2010 at 7:20 PM

No problem you are more than welcome, if you need any assistance with it don't hesitate to give me a shout.

B.

Jun 28, 2011 at 6:03 PM

We've added suppport for presenting exceptions, here's the updated xsl:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/> 

<xsl:template match="/">
<xsl:apply-templates select="/cruisecontrol/build/*[local-name()='StatLightTestResults']" />
</xsl:template>

<xsl:template match="/cruisecontrol/build/*[local-name()='StatLightTestResults']">
  <html>
  <body>

 <table border="1" cellSpacing="0" cellPadding="5" >
     <thead style="text-aliagn: center;">
       <td>Number of Tests</td>
       <td style="background-color: yellow; color:black;">Ignored</td>
       <td style="background-color: fireBrick; color: white;">Failed</td>
     </thead>

     <tr style="text-align: center;">
        <td><xsl:value-of select="@total"/></td>
        <td><xsl:value-of select="@ignored"/></td>
        <td><xsl:value-of select="@failed"/></td>

     </tr>
   </table>
  <h2>Test Results</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Test Name</th>
        <th>Result</th>
        <th>Test Duration</th>

      </tr>
      <xsl:for-each select="tests/test">
      <tr>
        <td><xsl:value-of select="@name"/></td>

       <xsl:choose>
         <xsl:when test="@resulttype = 'Passed'">
         <td style="text-align: center; font-weight: bold; background-color: forestGreen; color: white;">
           <xsl:value-of select="@resulttype"/>
         </td>
         </xsl:when>
         <xsl:when test="@resulttype = 'Failed'">
          <td style="text-align: center; font-weight: bold; background-color: fireBrick; color: white;">
            <xsl:value-of select="@resulttype"/>
          </td>
          </xsl:when>
         <xsl:otherwise>
         <td style="text-align: center; font-weight: bold; background-color: lightblue; color: black; ">
           <xsl:value-of select="@resulttype"/>
         </td>
       </xsl:otherwise>
       </xsl:choose>
        <td><xsl:value-of select="@timeToComplete"/></td>
      </tr>

      <xsl:choose>
      <xsl:when test="@resulttype = 'Failed'">
          <tr>
             <td colspan="3" bgcolor="#FF9900">
                <xsl:value-of select="exceptionInfo/message" />
             </td>
          </tr>
          <tr>
             <td colspan="3" bgcolor="#FF9990">
                <xsl:value-of select="exceptionInfo/stackTrace" />
             </td>
          </tr>

          <tr>
             <td colspan="3" bgcolor="#FF9900">
                <xsl:value-of select="exceptionInfo/innerExceptionInfo/message" />
             </td>
          </tr>
          <tr>
             <td colspan="3" bgcolor="#FF9990">
                <xsl:value-of select="exceptionInfo/innerExceptionInfo/stackTrace" />
             </td>
          </tr>

          <tr>
             <td colspan="3" bgcolor="#FF9900">
                <xsl:value-of select="exceptionInfo/innerExceptionInfo/innerExceptionInfo/message" />
             </td>
          </tr>
          <tr>
             <td colspan="3" bgcolor="#FF9990">
                <xsl:value-of select="exceptionInfo/innerExceptionInfo/innerExceptionInfo/stackTrace" />
             </td>
          </tr>

       </xsl:when>
       </xsl:choose>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>


Coordinator
Jun 28, 2011 at 10:15 PM

Great work. Thanks for the contribution...

Aug 30, 2011 at 8:34 AM

Thanks a bunch! Works like a charm ;-)

Regards, Morten G.