InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Interview With Aslak Hellesøy on Cucumber For .NET

Posted by Jon Arild Tørresdal on Nov 12, 2009

Sections
Process & Practices,
Development
Topics
Ruby ,
.NET ,
.NET Framework ,
Agile
Tags
Cucumber

InfoQ has interviewed Aslak Hellesøy, the creator of Cucumber on its recent support for .NET. Cucumber is an acceptance testing tool for Behavior Driven Development (BDD). At Agile2009, InfoQ’s Mark Levison reported from the Functional Test Tools Workshop that Matt Wynne and Richard Lawrence started to work on a .NET solution for Cucumber, later to be named Cuke4Nuke.

InfoQ: Could you briefly describe Cucumber and what it is?

Aslak: Cucumber is an acceptance testing tool that is designed for Behaviour Driven Development (BDD). It lets people with minimal technical knowledge describe requirements for a system. This is done by providing concrete examples of how they want the system to behave, in plain text. This is expressed in plain language such as "Then there should be $5000 on Bob's savings account".

This plain text starts its life as a requirements specification for code that has yet to be written. As the code is written, the same text also becomes an automated regression/acceptance test. Some people call it executable requirements.

BDD tools come in two flavours - the "unit testing" flavour (such as NSpec and RSpec) and the higher level acceptance testing flavour such as Cucumber, JBehave or other clones of these tools. Cucumber's main goal is to involve more people and roles in acceptance testing and requirements, and make it an enjoyable (addictive) experience.

InfoQ: How would you say Cucumber differ from tools like Fit/Fitnesse?

Aslak: I'll start by explainging how Cucumber is similar to FIT. Both FIT and Cucumber are command line tools. (Fitnesse is essentially a wiki on top of FIT).

Test language
Both FIT/Fitnesse and Cucumber execute acceptance tests written in a high level language. FIT only understands HTML, while Fitnesse simplifies this by offering Wiki syntax to write tests. In FIT/Fitnesse all tests have to be in a table form.

Cucumber on the other hand lets users write tests in plain text files in almost free form English. Ou Français. Eller norsk. или Русский. It supports almost 40 spoken languages. In essence, Cucumber recognises lines that start with the keywords "Scenario", "Given", "When" or "Then". This kind of language lends itself better to expressing *behaviour* than tables, which tend to be more about *data*.

Of course, Cucumber also lets you use tables interspersed with your plain text, so you can write tests that are a mix of behaviour oriented and data oriented. The funny thing is, Fitnesse now lets you use Scenario, Given, When and Then in tables, so there is definitely inspiration going both ways. It's friendly competition.

Here is an example of a Cucumber .feature file mixing tables into the text:

# language: en
Feature: Addition
  In order to avoid silly  mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scenario Outline: Add two numbers
    Given I have entered <input_1> into the calculator
    And I have entered <input_2> into the calculator
    When I press <button>
    Then the result should be <output> on the screen

  Examples:
    | input_1 | input_2 | button | output |
    | 20      | 30      | add    | 50     |
    | 2       | 5       | add    | 7      |
    | 0       | 40      | add    | 40     |

Programming language
Both Fit and Cucumber needs "glue" code that sits between the high level language and the code under test. In FIT this is called fixtures, in Cucumber it is called step definitions. Cucumber lets you write step definitions in C#, Java, Scala, Clojure, Groovy, Javascript, Ioke and Ruby, so Cucumber is more versatile than FIT in this regard.

Here is a step definition in C# that matches entering numbers into a calculator - from the example above:

[Given(@"^I have entered (\d+) into the calculator$")]
public void EnterNumber(double n)
{
  _calculator.Push(n);
}
Editor
FitNesse's big advantage over Cucumber right now is the Wiki. Cucumber doesn't (yet) have a web based editor that lets non-technical people edit the acceptance tests. There is a tool called Lowdown, but it doesn't support tables, so it quickly falls a little short. JetBrains' RubyMine has a decent editor, but it's geared towards programmers.

InfoQ: As I understand it, Cucumber now supports two different ways of using the tool on .NET. Could you briefly describe these two and their pros/cons?

Aslak: That's right. Cucumber itself is written in Ruby, so it needs a Ruby interpreter to run. The first option for .NET is to run it on IronRuby. If you do this, you currently have to write your step definitions in Ruby code (that will talk to your .NET code). However, there are plans to change this so you can use C# as shown above.

The other option you have is to use something called Cuke4Nuke. This is the tool that lets you write step definitions in C# and forget all about ruby code. This tool actually uses MRI (Matz Ruby Interpreter, the original, which is written in C) and sends commands to a local C# socket server, which will run your step definitions. But to the user that's all transparent - they will only ever deal with .feature files, .cs files and the cuke4nuke command line tool.

I'd also like to mention a third project - SpecFlow. This project is 100% .NET and doesn't share any code with Cucumber, but it tries to replicate as much of the behaviour as possible. Plus - it has Visual Studio integration. I'm talking to the SpecFlow team about collaborating with Cucumber, and it looks like we're going to use the same feature file parser. This would make Cucumber's test language (which is called Gherkin) more consistent across tools.

InfoQ: What is on top of your wish list for Cucumber?

Aslak:
Short term:

  • Speed, using a faster parser. We have done great progress on this in the Gherkin project, which uses Ragel.
  • A new website. The wiki is a great resource, but the information needs to be restructured to be more accessible to newcomers, non-ruby programmers and non-programmers in general.

Long term:

  • An easy to use collaborative environment for editing and running features. There is already RubyMine and LowDown, but I have some different ideas myself.
  • Ability to edit and store tests in more formats and more mediums. For example on a set of wiki pages on your intranet. Or Word documents. What made FIT popular in its early days was Excel support, and in order to win the non technical side over we need to support their preferred tools. Or give them better ones.

InfoQ: Thanks for taking the time to talk to InfoQ.

  • This article is part of a featured topic series on Agile

Related Sponsor

In today’s hyper-competitive world, later may be too late to adopt Agile development and this Roadmap for Success will help you get started. Download "Agile Development: A Manager's Roadmap for Success" now!

Having seen the birth of Cuke4Nuke... by Mark Levison Posted
It's an old post but... by simone basso Posted
  1. Back to top

    Having seen the birth of Cuke4Nuke...

    by Mark Levison

    ...at the AA-FTT meeting before Agile2009, I was impressed by how flexible and adaptive Aslak was. Richard, Matt, Declan, myself and a few others were discussing possible approaches and Aslak came up with a solution that made the .NET (and all future languages) version easier to achieve.

    Part of what I appreciate is it gives our clients a wide range of open source frameworks they can consider for their acceptance tests Cucumber/RobotFramework/FitNesse/...

    Cheers
    Mark Levison
    Co-Founder and Consultant - TheAgileConsortium

  2. Back to top

    It's an old post but...

    by simone basso

    For anyone reading this post right now, and thinking about implementing BDD in .NET, have a look at specflow.org/.
    It uses the same syntax as Cucumber (Gherkin) and is deeply integrated with VS 2010.

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.