Simon Harriyott

Using MSBuild and the build machine for integration testing

My build machine has been very useful in running unit tests for the various components of the project I'm working on, but having recently spent several days trying to integrate a couple of components to run on a clean machine, I realised that unit testing isn't enough. There were three components that I wanted to use on a clean machine:
  • the file watcher service, that monitors a directory for XML files and kicks off...
  • the XSLT engine, which converts the XML into a different format and
  • the import component, which reads the converted XML and inserts the data into SQL Server
These components all have passing unit tests that are automatically run a couple of times a day. There are, by definition, no unit tests that run the three components together. So today I wrote an MSBuild task to automate the integration testing of these components. There was a little pre-work, like creating a merge module for each component, and an installer, and tweaking the configuration files that are installed by default. (Annoyingly, we're still using Beta 2 of .NET, so there's no MSBuilding the .vdproj files yet.)

The MSBuild task took about 3 hours to write and perfect, and in order:
  • Checks that the relevant directories exist, and test files are present
  • Counts the rows in the destination SQL Server table
  • Copies some test files in the watched directory
  • Waits a few seconds
  • Counts the rows in the destination table again
  • Makes sure that the correct number of rows have been inserted
Creating an MSBuild task is really straightforward. Derive a class from Task, add some public properties, and code the stuff. For some slightly more technical details, see Barry Dorrans' presentation and code samples from the last DeveloperDeveloperDeveloper event.

I then created a new MSBuild project file, which:
  • Runs the installer (silently)
  • Starts the file watcher service
  • Runs the integration test task
  • Stops the file watcher service
  • Uninstalls it all again
This worked beautifully, so I added it at the end of the main build script using an MSBuild task. So now I have integration testing running on the daily build machine.
29 November 2005