Cucumber Tests as First Class Citizens in TeamCity
September 3rd, 2009
TeamCity is a great continuous integration server, and has brilliant built in support for running NUnit tests. The web interface updates automatically as each test is run, and gives immediate feedback on which tests have failed without waiting for the entire suite to finish. It also keeps track of tests over multiple builds, showing you exactly when each test first failed, how often they fail etc.
If like me you are using Cucumber to run your acceptance tests, wouldn’t it be great to get the same level of TeamCity integration for every Cucumber test. Well now you can, using the TeamCity::Cucumber::Formatter from the TeamCity 5.0 EAP release.
JetBrains, the makers of TeamCity, released a blog post demostrating the Cucumber test integration, but without any details in how to set it up yourself. So I’ll take you through it here.
Getting a Copy of the TeamCity Cucumber Formatter
The latest TeamCity EAP contains the new Cucumber Formatter hidden deep in it’s bowels. Rather than make you wade through it all, I’ve extracted the relevant files and they are available to download here:
Download the TeamCity Cucumber Formatter
The archive contains the formatter and the TeamCity library files it requires to run. Extract the archive in your project root and it will add the following files:
features/
support/
jetbrains-teamcity-formatter.rb
lib/
teamcity/
[some support and utility files]If you want to locate these files within the TeamCity EAP yourself, download the TeamCity 5.0 EAP War file and extract it. Then from within the war unzip WEB-INF/plugins/rake-runner-plugin.zip. And from within the rake-runner-plugin look at rake-runner/lib/rb/patch/bdd/teamcity/cucumber/formatter.rb and all the files in rake-runner/lib/rb/patch/common/teamcity/.
The formatter in my download has been tweaked to look in a new location for the teamcity support files, and has been changed to be a single class in a module named JBTeamCityFormatter (to ease calling it from the command line).
The relevant changes in the file are:
14 15 16 17 18 19 20 21 | $: << File.expand_path(File.dirname(__FILE__) + '/../../lib/') require 'teamcity/runner_common' require 'teamcity/utils/service_message_factory' require 'teamcity/utils/runner_utils' require 'teamcity/utils/url_formatter' class JBTeamCityFormatter < ::Cucumber::Ast::Visitor |
Setting up Cucumber to use the TeamCity Formatter
Once you have the formatter installed you can use it as with any Cucumber formatter by adding it as a command line parameter:
cucumber features -f JBTeamCityFormatterTo use it with TeamCity, add a profile your cucumber.yml file that runs all your features using the new formatter:
cucumber.yml
default: features -q teamcity: features -q --no-c -f JBTeamCityFormatter
Running Cucumber with TeamCity
Now when you run Cucumber within TeamCity (using the teamcity profile) it will report tests in real time, with all the feedback you are used to. Just add a call to the Cucumber executable to your build script (NAnt, MSBuild, Ant, Rake, etc).

Enjoy the new found treatment of Cucumber tests as first class citizens in TeamCity!
Running JS Test Driver in Team City
August 25th, 2009
JS Test Driver is a great new Javascript Testing Framework from the guys at Google. It provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this introduction to JS Test Driver by Miško Hevery for a great overview.
Getting JS Test Driver up and running on your development workstation is easy enough. But how about on a continuous integration server such as TeamCity?
It’s easy, just follow the instructions below!
Install Java and the JS Test Driver jar on all the build agents
JS Test Driver is packaged as a Java jar, and therefore all the TeamCity build agents will need a copy of Java and the JS Test Driver jar in order to run the tests.
- For each Build Agent
- Download Java and install it.
- Download the JS Test Driver jar and save it to
c:\TeamCityBuildTools\JSTestDriver\(or whichever location you wish)
Configure JS Test Driver
This guide assumes you already have JS Test Driver and some tests set up on your local machine. If not see this introduction to JS Test Driver by Miško Hevery.
Just make sure that the JS Test Driver config file is set to connect to the local machine, on port 9876 (on another port of your choice). E.g.
server: http://localhost:9876 load: # list of files to load here...
Configure your build process to call JS Test Driver
Now that we have JS Test Driver installed on our build machines, and configured correctly, let’s call it from our build process. At 7digital we are using MSBuild, so we can create a JSTestDriver Target as so:
<Target Name="JSTestDriver"> <Message Text="##teamcity[progressMessage 'Running JS Test Driver']" Importance="high" /> <Message Text="-------- Running JS Test Driver --------" Importance="high" /> <PropertyGroup> <JSTestDriverJar>"$(BuildToolsPath)\JSTestDriver\jsTestDriver.jar"</JSTestDriverJar> <ConfigFile>"$(SolutionFolder)\jsTestDriver.conf"</ConfigFile> <IEPath>"C:\Program Files\Internet Explorer\iexplore.exe"</IEPath> <OutputDir>"$(SolutionFolder)\output\JSTestDriver"</OutputDir> </PropertyGroup> <Exec Command="java -jar $(JSTestDriverJar) --port 9876 --browser $(IEPath) --config $(ConfigFile) --tests all --testOutput $(OutputDir)" /> </Target>
The important points here are that you have the properties configured correctly (JSTestDriverJar, ConfigFile, etc) for your individual setup.
The Exec command will automatically create a JS Test Driver server, launch IE, and run all the tests. The test results will be output to the OutputDir in a JUnit compatible xml format. See the JS Test Driver continuous integration page for more information.
Once you have created this Target, ensure it is called by your standard bulid Target by adding it as a dependancy:
<Target Name="BuildAndUnitTest" DependsOnTargets="Compile;JSLint;JSTestDriver;NUnit" />Have TeamCity pick up the test results
If you run your build through TeamCity now, you will see that it runs all your Javascript tests using JS Test Driver. But it doesn’t report any results. And test failures don’t stop the build.
Luckily TeamCity can import the JS Test Driver output xml, because it is JUnit compatible.
- Select the build which is running the JS Test Driver tests
- Click
Edit Configuration Settings - Click on build step 3 (e.g.
Runner: MSBuild) - Under the
XML Report Processingsection, chooseAnt JUnitfrom theImport datafrom dropdown - In the
Report pathstext area add the relative path the the JS Test Driver output file (e.g.output\JSTestDriver\TEST-com.google.jstestdriver.1.xml) - Click
save!
Now when you run your build again you will see your JS Test Driver tests showing up in the Tests tab, and test failures now stop the build.
Your Javascript unit tests now sit as first class citizens within TeamCity!
