Friday, December 30, 2011

Continuous Integration for Visual Studio Load Test via Cruise Control .NET

In the previous post we created a load test for the book store service. We developed a functional test per user scenario for generating synthetic load and walked through the entire process of creating and running the Load Test.

In this post we will see how the Load Test can be executed continuously via 'Cruise Control .NET' (CCNet) and provide immediate feedback via CCNet's portal.

here's a quick video that shows the load tests run from CCNet and the results presented in CCNet's portal.

Throughout the post, we'll register the Load Test to run via CCNet and extend the portal to show a summary of the load test results using the trx file generated by the test.


In the next post, we'll take a step forward and add a custom task to CCNet that will query the database and generate a custom xml summary that includes performance highlights, comparison with previous runs and exception details for all the tests that have failed. We will also extend the portal to present the custom content.


The source code is available here

Getting Started!

We'll start by installing CCNet from here

Once the installation is complete, we'll add the appropriate project/tasks to CCNet configuration file located here: %Program Files%CruiseControl.NET\server\ccnet.config

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
   <project name="LoadTesting-BookStoreService">
    <!-- Run tests every 4 hours-->
        <intervalTrigger name="continuous" seconds="14400" 
        buildCondition="ForceBuild" initialSeconds="30" />
        <description>Delete previous results</description>
        <!-- Timeout after 1 minute-->
        <!-- Timeout after 15 minutes -->
        <!-- Tests -->
            C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe
            /testcontainer:Tests\BookStoreLoadTest.loadtest /resultsfile:Results.trx
        <description>Run load tests</description>
        <!-- Timeout after 20 minutes-->
            <!-- Add the result file to the build log -->
      <xmllogger />      

With the configuration above, CCNet will do the following (every 4 hours or one demand):

  1. Delete the results from last run (MSTest doesn't override the results)
  2. Build the BookStore.sln
  3. Run the load test.
  4. Add the result trx to the build log (so we can present it in the portal)

Now. we need to extend the CCNet portal to present the results. We need to:

  1. Create xsl that transform the results trx to HTML
  2. Copy the xsl to '%Program Files%\CruiseControl.NET\webdashboard\xsl'
  3. Add link to the xsl to 'Program Files (x86)\CruiseControl.NET\webdashboard\dashboard.config'
  4. Restart IIS

Here's the xsl:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='Results']/*[local-name()='LoadTestResult']" />
  <xsl:template match="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='Results']/*[local-name()='LoadTestResult']">
      Summary for '<xsl:value-of select="@executionId"/>'
    <xsl:apply-templates select="*[local-name()='Summary']/*[local-name()='TestSummaries']">
    <xsl:apply-templates select="*[local-name()='Summary']/*[local-name()='TransactionSummaries']">
  <xsl:template match="*[local-name()='Summary']/*[local-name()='TestSummaries']">
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td style="background-color: fireBrick; color: white;">Failed</td>
        <td style="background-color: darkblue; color: white;">Duration</td>
      <xsl:apply-templates select="./*" />
  <xsl:template match="*[local-name()='TestSummary']">
        <xsl:value-of select="@testName"/>
        <xsl:value-of select="@totalTests"/>
        <xsl:value-of select="@testsFailed"/>
        <xsl:value-of select="@averageDuration"/>
  <xsl:template match="*[local-name()='Summary']/*[local-name()='TransactionSummaries']">
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td style="background-color: darkblue; color: white;">Elapsed Time</td>
        <td style="background-color: darkblue; color: white;">Response Time</td>
      <xsl:apply-templates select="./*" />
  <xsl:template match="*[local-name()='TransactionSummary']">
        <xsl:value-of select="@transactionName"/>
        <xsl:value-of select="@transactionCount"/>
        <xsl:value-of select="@elapsedTime"/>
        <xsl:value-of select="@responseTime"/>

Here's the modified dashboard.config:

<?xml version="1.0" encoding="utf-8"?>
      <!-- Update this list to include all the servers you want to connect to. NB - each server name must be unique -->
        backwardsCompatible="false" />
      <farmReportFarmPlugin categories="false" />
      <cctrayDownloadPlugin />
      <administrationPlugin password="Pa$$word1" />
      <serverReportServerPlugin />
      <projectStatisticsPlugin xslFileName="xsl\StatisticsGraphs.xsl" />
      <projectReportProjectPlugin />
      <viewProjectStatusPlugin />
      <latestBuildReportProjectPlugin />
      <viewAllBuildsProjectPlugin />
          <!-- Updated! Adding xsl for presenting load test results -->
      <buildLogBuildPlugin />
      <simpleSecurity />

We are done!

Now we can start the 'Cruise Control .NET' service or run the executable process from %Program Files%CruiseControl.NET\server\ccnet.exe.

Once the CCNet service/process is started, we can go ahead and trigger a build.The simplest way is to browse to the portal (installed and deployed to IIS during the installation) and force a build.


Once the build is complete, we can see the results here:


Another way to trigger a build is using the CCtray client application. The application can be installed from the portal.


CCTray installation can also be found here: '%Program Files%\CruiseControl.NET\webdashboard\cctray'

Once the installation is complete, the CCTray application will be available in the Task Bar (Notification Area). We need to add the project, right click and select 'Force Build'.