Configuring CruiseControl.Net with SVN, Visual Studio 2008 and MSBuild

Integrating CruiseControl.Net into our development environment was a fairly simple process. The steps below detail what was required to get CruiseControl.Net to pull changes from SVN, on an interval trigger, then build using Visual Studio 2008 via MSBuild.

For details on configuration options for CruiseControl, refer to the online documentation.

Installing CruiseControl.Net

1. Download the latest installation files. The latest release at the time of this article is 1.5.725.

2. Run the installation file and place the files in the default directory C:\Program Files\CruiseControl.NET.

CruiseControl.Net Overview

CruiseControl can run either as a stand-alone exe or by running as a service. It’s important to run the stand-alone application when building your config file at first. The exe will run in a command window displaying everything that’s happening within your CruiseControl.Net server. It’s an essential tool to debugging your config file.

Stand alone application is located in: C:\Program Files\CruiseControl.NET\server\ccnet.exe

The CruiseControl.Net service is named CruiseControl.Net Server (in Control Panel/Administrative Tools/Services)

Editing Your Configuration File

1. Open CruiseControl.Net’s main configuration file

Locate file ccnet.config in C:\Program Files\CruiseControl.NET\server.

2. Add your project


<project name="Public Website">

  <workingDirectory>d:\build\trunk\Website</workingDirectory>

  <webURL>http://server1/ccnet/server/local/project/testProject/ViewLatestBuildReport.aspx</webURL>

  <triggers>

    <intervalTrigger name="continuous" seconds="30" buildCondition="ForceBuild" initialSeconds="30"/>

  </triggers>

  ...

</project>

The project contains the following tags:

  • <workingDirectory> – The directory CruiseControl.Net will use to manage your project.
  • <webURL> – The build report for the project you’re configuring.
  • <triggers> – How often CruiseControl will pull down files from source control and build the solution. The example above has an interval trigger of 30 seconds. Every 30 seconds CruiseControl will check source control for modifications. If they exist, a build will be triggered.

3. Define SVN as your Source Control


    <sourcecontrol type="svn">

      <trunkUrl>https://MyServer/svn/website/trunk</trunkUrl>

      <workingDirectory>d:\build\Website</workingDirectory>

      <username>dave</username>

      <password>dave123</password>

      <timeout units="minutes">30</timeout>

    </sourcecontrol>

Within the <sourcecontrol> tag, our SVN configuration is defined:

  • <trunkUrl> – Location of the main trunk for our project.
  • <workingDirectory> – Directory to place all files pulled down from SVN when doing a build.
  • <username> / <password> – SVN credentials

4. Add an MSBuild task

A basic MSBuild task is below, essentially building our solution from the command prompt using Visual Studio. Build options used are debug and rebuild all.

    <tasks>

      <msbuild>

        <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>

        <workingDirectory>D:\build\Website</workingDirectory>

        <projectFile>MyWebSolution.sln</projectFile>

        <buildArgs>/p:Configuration=Debug /v:diag /t:rebuild</buildArgs>

        <timeout>120</timeout>

      </msbuild>

    </tasks>

5. Configure Notifications

CruiseControl.Net does a great job of notifying when builds break. The CCTray, CruiseControl’s notification icon stays in the bottom right-hand corner of your desktop in your system tray. Your icon turns green on successful builds, yellow when building and red when the build fails.

If this isn’t enough, you can setup email notifications. If you work in an environment where you have outsourced development, it helps to send out instant notifications if someone breaks the build.

    <publishers>

      <xmllogger logDir="D:\build\Website\BuildLogs" />

      <email mailport="25" includeDetails="TRUE">

        <from>no-reply@wordpress.com</from>

        <mailhost>mail.MyServer.com</mailhost>

        <users>

          <user name="Dave" group="BuildGuru" address="david.scott.peterson@gmail.com" />

        </users>

        <groups>

          <group name="BuildGuru">

            <notifications>

              <notificationType>Failed</notificationType>

              <notificationType>Fixed</notificationType>

              <notificationType>Exception</notificationType>

            </notifications>

          </group>

        </groups>

      </email>

    </publishers>

Server Configuration

The CruiseControl.Net service needs to run as an account that has access to the source code repository. Since our source control is listed under HTTPS, but with no valid SSL certificate, we have to convince CruiseControl to ignore the certificate error. The CruiseControl.Net user account needs to permanently accept the certificate exception, otherwise, CriuseControl will fail to pull down the latest code from SVN.

Steps to creating the CruiseControl.Net service account:

1. Create a CruiseControl.Net local user account.

New CruiseControl.Net User

Create a new user for the CruiseControl.Net service

2. Setup service to run as new CruiseControl.Net local user account.

CruiseControl.Net Service Settings

Run the service as your new CCNetUser local account

3. Accept SSL exception for CruiseControl.Net local user account.

Accept the SSL Certificate Permanently

Accept the SSL Certificate Permanently

Login to the server hosting CruiseControl.Net using the account created in step 1. Open a command prompt and type: ‘svn list https://<svn repository location>’. When prompted to accept the certification exception, type ‘p’ for permanently.

Full CCNet.config

<cruisecontrol>

  <!– This is your CruiseControl.NET Server Configuration file. Add your projects below! –>

 

  <!– Trunk –>

  <project name=My Website>

    <workingDirectory>d:\build\trunk\Website</workingDirectory>

    <webURL>http://server1/ccnet/server/local/project/testProject/ViewLatestBuildReport.aspx</webURL>

    <triggers>

      <intervalTrigger seconds=30 buildCondition=IfModificationExists/>

    </triggers>

    <sourcecontrol type=svn>

      <trunkUrl>https://MyServer/svn/website/trunk</trunkUrl>

      <workingDirectory>d:\build\Website</workingDirectory>

      <username>dave</username>

      <password>dave123</password>

      <timeout units=minutes>30</timeout>

    </sourcecontrol>

    <tasks>

      <msbuild>

        <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>

        <workingDirectory>D:\build\Website</workingDirectory>

        <projectFile>MyWebSolution.sln</projectFile>

        <buildArgs>/p:Configuration=Debug /v:diag /t:rebuild</buildArgs>

        <timeout>120</timeout>

      </msbuild>

    </tasks>

    <externalLinks>

      <externalLink name=My Website url=http://MySite.com />

    </externalLinks>

    <publishers>

      <xmllogger logDir=D:\build\Website\BuildLogs />

      <email mailport=25 includeDetails=TRUE>

        <from>no-reply@wordpress.com</from>

        <mailhost>mail.MyServer.com</mailhost>

        <users>

          <user name=Dave group=BuildGuru address=david.scott.peterson@gmail.com />

        </users>

        <groups>

          <group name=BuildGuru>

            <notifications>

              <notificationType>Failed</notificationType>

              <notificationType>Fixed</notificationType>

              <notificationType>Exception</notificationType>

            </notifications>

          </group>

        </groups>

      </email>

    </publishers>

  </project>

</cruisecontrol>

Advertisements

Creating Selenium Unit Test Suites with NUnit

When looking for a way to test our websites by using web macros, directly interacting with the rendered presentation of our sites, I ran across quite a few test suites. Both Waitr and Selenium stood out as the more stable, extensible and easy to incorporate test suites out there. Selenium, however, seemed to offer easy implementation on a .Net platform. Once properly setup, Selenium unit tests are as easy to create as opening Firefox, browsing the site you want to test and record your unit test macro as you navigate from one page to another.

Selenium comes in with a few different installation components and programs:

  • Selenium IDE – Firefox plugin used to create the unit tests.
  • Selenium Core – Core libraries for .Net/C#.
  • Selenium Remote Control -Allows for managing Selenium unit tests with multiple broswers simultaneously (includes the Selenium Core libraries).
  • Selenium Grid -Load balance your tests across multiple servers.

Installing Selenium IDE

Download and install the Selenium IDE. This will add a “Selenium IDE” option under tools in your Firefox browser.

Installing Selenium Remote Control

Download the Selenium RC installation files and extract to a location on your test server. For this example, I extracted to c:\Selenium-Remote-Control\.

Starting the Selenium Server is as easy as running “java -jar selenium-server.jar” from the directory of your Selenium Server installation. Since this is a java-based application, you may be required to download the latest version of java prior to successfully starting the Selenium Server.

Starting selenium server

Starting the Selenium Server using Java v1.6.017

If your Selenium Server output resembles something like above, then you’re in business.

Installing NUnit

Installing Selenium Server is not enough. You must also install NUnit to drive the C# generated unit tests that target the Selenium server.

Download the NUnit installation files and install the software to your test server.

Creating Your First Selenium Unit Test

1. Open Firefox

2. Go to tools and select Selenium IDE

Starting Selenium IDE

Starting the Selenium IDE

3. Once the IDE opens, it defaults to recording every action you take on a given website. Select the output that the IDE will use to generate your unit test. For this example, we’re using C#.

Choose C#

Choose C# to output your test

4. While still within Firefox, click through the website for which you want to create a unit test. Every action you take will be recorded by the IDE, with your unit tests generated immediately.

5. When done generating your test, click on the record/stop button to end the IDE. You’ll see your complete unit test within the Source tab of the Selenium IDE window.

Selenium IDE Record Actions

Record your actions in C#

Example Unit Test Generated by the Selenium IDE

Clicking through w3school’s website generated the following code:

Selenium Test Code

Snapshot of Generated Code

Steps to generate the code above:

Clicked on Next Chapter

Clicked on "Next Chapter"

Clicked on Try it Yourself

Clicked on Try it Yourself

Edited the HTML

Edited the HTML

Running The Example Test

1. Take the C# code generated by the Selenium IDE and add it as a class to a new Visual Studio project.

2. Add references to your project for the following dll’s

  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\nmock.dll
  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\nunit.core.dll
  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\nunit.framework.dll
  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\ThoughtWorks.Selenium.Core.dll
  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\ThoughtWorks.Selenium.IntegrationTests.dll
  • C:\Selenium-Remote-Control\selenium-dotnet-client-driver-1.0.1\ThoughtWorks.Slenium.UnitTests.dll
Selenium Project References

Selenium Project References

3. Build the solution.

4. Open NUnit. Select File > Open Project… and select the your project’s compiled assembly.

5. Within NUnit, highlight your unit test class name and click on Run.

NUnit Run

Sit back and watch the show. NUnit will kick off the unit test, which runs the compiled code generated by the Selenium IDE. You’ll see the Selenium Server output the commands in the command prompt window. Selenium Remote Control Server then opens, which triggers the opening of a browser window to run the recorded Selenium unit test. NUnit will then report back the results of the test.

Selenium in Action

Selenium in Action