Agile testing: Getting agile tests incorporated into your sprints using BDD and Cucumber in C++

Posted by:

Agile testing

We’ve adopted agile testing in the form of Behavior Driven Development (BDD) as part of our agile development process, and use Cucumber features extensively on Ruby on Rails web application projects for our own customer software development projects, although we have done Java, Delphi and C# implementations of agile testing as well using BDD and Cucumber.

Cucumber for C++

A recent project called for the introduction of agile testing using BDD to an existing Windows code base, with a large portion of the code being developed in C++. Cucumber-cpp is currently the most active implementation of Cucumber for C++. It can be used on Linux, Mac OS X as well as Windows.

Cucumber-cpp prerequisites

The current cucumber-cpp library relies on at least one of the following libraries:

[list_icon color=”blue” type=”icon_arrow”]
  • Boost 1.40 or later
  • GTest 1.4 or later
  • CppSpec development branch
  • GMock 1.6 or later

We’ve decided to use Boost, specifically version 1.5.2 (the most current version at the time). The following software was used on Windows 8:

[list_icon color=”blue” type=”icon_arrow”]
  • CMake – version 2.8.10
  • Boost – version 1.52.0
  • Cucumber-cpp – master branch
  • Visual Studio 2012
  • Ruby 1.9.3 with the cucumber gem

Installing cucumber-cpp on Windows

Installing cucumber-cpp and the included example on Windows proved to be quite a challenge, largely as a result of the dependency on Boost and it’s test framework.  Installation on Linux was trivial in comparison, and the instructions at the library’s Github page worked as expected (for use on Linux).

Step 1: Install Ruby

There are various options to install Ruby on Windows, we’ve used RubyInstaller 1.9.3-p374 as found on the Ruby Installer web site.

Verify the installation in a Windows console:

ruby -v

Once Ruby is installed, install the cucumber gem:

gem install cucumber

Step 2: Install CMake 2.8.10

We’ve decided to use the pre-compiled binary as found on the CMake web site, and it installed perfectly without any issues.

Step 3: Install Boost 1.52.0

Boost was another kettle of fish, especially since it’s unit tests must be included to ensure that cucumber-cpp can be compiled and linked properly. Download the source from the Boost web site and extract into C:\Boost\boost_1_52_0, and then use the following to build Boost (warning, this will take quite a while to complete):

cd c:\Boost\boost_1_52_0
.\b2 –prefix=c:\Boost –build-type=complete –with-thread
–with-regex –with-system –with-date_time –with-test
–with-filesystem –with-chrono –with-program_options
address-model=32 install

Once built, add C:\Boost\lib to the Window system PATH (to ensure that the applicable .dll files are found at runtime when running the executables that will be built in Visual Studio.

Step 4: Build the cucumber-cpp library and example

Download or clone the latest version of cucumber-cpp from the github repository into C:\Cucumber\cucumber-cpp and follow these instructions to prepare a Visual Studio project file:

cd c:\Cucumber\cucumber-cpp
cmake -E make_directory vsprj
cmake -E chdir vsprj cmake -G”Visual Studio 11″

Once done, open C:\Cucumber\cucumber-cpp\vsprj\Cucumber-Cpp.sln with Visual Studio 2012 and build the project.

Running the features

Two steps in a Windows terminal or console are required to run the given example features (change to C:\Cucumber\cucumber-cpp).

a) Run the cucumber-cpp listener

cd vsprj\examples\Calc\Debug
start  BoostCalculatorSteps.exe

A new terminal window should load up, with ‘Listening on port 3902’ as the output.

b) Run features

cd examples\Calc
cucumber CalcFeatures

If all goes well, you should see the following output (showing output inside console2 with ansicon):

agile testing: windows cucumber cpp output screenshot

Bonus feature: Improve the Windows console output

The default output are not colour coded (as one would expect), we’ve installed console2 with ansicon (x86 on Windows 8) to fix this.

More information can be found here:

References and resources

[list_icon color=”blue” type=”icon_arrow”] [/list_icon]


Interesting Infoware Studios Bookmarks

    WP HTTP Error: A valid URL was not provided.

  • Delicious See on delicious : ruby

About the Author:

  Related Posts


  1. johan  January 25, 2013

    A big thanks to Paolo Ambrosio who helped me to get this going, esp. with the Boost compilation parameters!

  2. Tania van Wyk de Vries  January 26, 2013

    And so we get the year going by sharing some great work. Thanks Johan!

  3. Jainyzau  August 14, 2014

    Thank you very much for posting this. I’ve tried several hours on this but failed, and finally made it after reading your post.

    • mispahc  August 14, 2014

      Glad you found it useful Jainyzau!