Book Review – The Cucumber Book

The Cucumber Book

Title: The Cucumber Book – Behaviour-Driven Development for Testers and Developers

Authors: Matt Wynne, Aslak Hellesøy

Rating: 4/5

Overall, a solid introduction to the Cucumber testing tool, and BDD in general. About the only criticism I have of it is that it’s perhaps a little bit too Ruby focused – an example of working with an application or a database without leveraging Rails would have been nice.

Man, where does the time go? I wanted to do one of these reviews a week – or at least a fortnight – and now it’s been over two months! Not a good start. But this book was worth taking the time on. Heck, this book is so cutting edge, it isn’t even published yet (at the time of writing) – I bought it as a PragProg Beta book. Actually, that’s one of the reasons I took so long to get the review out – there were several major updates to the book while I was reading it, and I had to read it again at the end to make sure I didn’t miss anything. [There were other reasons as well – such as the new Janny Wurts book coming out]

The book is very solidly written, with many excellent worked examples that give you a good feel for how the tool can be used. The progression from novice through to competent is good – you can pick up this book and learn how to write good feature tests quite readily.

The book is laid out into three sections. The first introduces Cucumber and the Gherkin language (used to write the test specifications), and goes over the process of writing and maintaining Cucumber tests in Ruby. The second section is a worked example – the authors demonstrate how to use Cucumber to test a realistic application, including access to a database and even messaging infrastructure. The last section covers a variety of specific problems – testing a web application via a browser, integrating tests into a build server, testing AJAX apps, and others.

The first section is the best, by far. The authors take you from knowing nothing about Cucumber to being able to develop a strong set of automated tests – by the time you get through this section, you should know all about Gherkin, using tables to specify examples, laying out features, common patterns and anti-patterns, and so forth. Personally, I’ve been watching Cucumber for well over a year, and I managed to pick up quite a lot from this section myself. The only problem I have with the first section is that it assumes you know Ruby. Not a real problem for me – I have enough Ruby knowledge to get by – but if I was coming in as a non-technical tester looking to pick up some BDD skills, it would be a bit rough. This area could have used a sidebar with some “Here’s where to go to learn Ruby” (It’s mentioned in the preface, but the classic Pickaxe book is a bit heavy for non-technical types – I would probably have recommended something more like Everyday Scripting with Ruby – or even some online resources). Similarly, when the authors start on writing the implementations of the Cucumber steps, they gloss over a bit on the mechanics of asserting – though here they do provide links.

Chapter 6 – “When Cucumbers Go Bad” – is definitely the prize winning chapter for me. The advice on structuring your tests is superb, and anyone serious on using a tool like Cucumber needs to read that chapter.

The second section is decent. The chapter on integrating with asynchronous behaviour in particular is a good read – though I think they could have made the discussion on the Service Manager (a tool that will launch required apps) a bit more visible – this approach is handy if you’re using Cucumber to test non-Ruby apps (which happens to be what I’m focusing on). However, by the end of this section, the implicit knowledge of Ruby – and Ruby libraries – starts to grow. For example, the section of testing a database assumes you know ActiveRecord. Now, ActiveRecord may not be hard to learn – but I don’t know it. I do know it’s a bit opinionated though (and that’s not a bad thing!), and would have liked a bit more guidance on how to integrate ActiveRecord with a legacy application.

The third section is a semi-random selection of topics. Each chapter is coherent in and of itself, but there’s no theme; this is the section where good ideas got put. There’s also a couple of overlaps – for example, when talking about testing a REST API, they briefly mention a tool called ‘childprocess’, which seems to do something similar to Service Manager.

The biggest let-down for me, personally, is that there isn’t much advice for how to integrate Cucumber into a legacy application that’s not written in Ruby. I’d have loved for a solid example of talking to a database, for example, that wasn’t designed with ActiveRecord in mind. I would also have liked to seen advice on how to fake out remote services, particularly remote web services that the application under test talks too. Other examples that I could see being compelling would be testing a GUI based app. It also wouldn’t have hurt to have had an appendix where they briefly summarised each of the gems mentioned in the book, and provided links to the relevant project pages (they did provide a list of versions, which is something).

(In hindsight, I should have got involved with the discussion forums while the book was being written… ;)

This book is definitely worth getting, but it won’t be the only book on BDD you should read – there’s enough uncovered ground to fill a book on “Cucumber Recipes”, for example. I would also recommend reading the related book “Specification by Example” – except that I haven’t read that myself yet, so I can’t.

Tools like Cucumber will be key to unlocking another layer of productivity and collaboration. Get used to it.

About these ads

6 thoughts on “Book Review – The Cucumber Book

      1. Matt Wynne

        I’ve actually managed to squeeze some significant changes in at the last minute. Based on your feedback, the database chapter is now much kinder on the reader who doesn’t know what ActiveRecord is, and gives them some more background, especially about how they could use it to connect to a legacy (non Ruby) system’s database.

        I’ve also dealt with some of those other issues you mentioned, explaining the reason why we’ve demonstrated both ServiceManager and ChildProcess, for example.

        You’re spot-on about the other topics that we could have covered. Many of the subjects you’ve suggested were in our dream table-of-contents, but when it came down to it, we couldn’t keep writing the book forever–some things just had to be cut out of scope.

        You’ll get an updated e-book soon, and I’d appreciate it if you can amend your review if you appreciate the changes we’ve made. I’m very grateful for your feedback, as I’m sure future readers of the final book will too.

  1. Paul

    I’ve been working through the examples in the book and can’t get the past the “Adding Feature”

    Here’s my adding.feature file:

    Feature: Adding

    Scenario Outline: Add two numbers
    Given the input “”
    When the calculator is run
    Then the output should be “”

    Examples:
    | input | output |
    | 2+2 | 4 |
    | 98+1 | 99 |

    My calculator_steps.rb file:

    Given /^the input “([^”]*)”$/ do |input|
    @input = input
    end

    When /^the calculator is run$/ do
    @output = `ruby calc.rb #{@input}`
    raise(‘Command failed!’) unless $?.success?
    end

    Then /^the output should be “([^”]*)”$/ do |expected_output|
    @output.should == expected_output
    end

    In the calc.rb file (which I put in the step_definitions directory) I have:
    print “4”

    When I run the test in RubyMine it raises the RuntimeError: Command failed!

    If I write something that forces that step to pass (i.e. unless 1 == 1) then I get an error RSpec::Expectations::ExpectationNotMetErrir: expected: “4” got: “” (using ==).

    Very frustrating when you buy a book and the examples don’t work. Any idea what I’m missing?

    Reply
  2. Robert Post author

    Paul, I’m not sure which version of the book you are using, or what format (PDF, Kindle, epub), but in the 0.9 build (the current one) in the PDF and ePub versions, the Scenario Outline looks like this:

    Feature: Adding
      Scenario Outline: Add two numbers
        Given the input “<input>”
        When the calculator is run
        Then the output should be “<output>”

    You need the bits in the angle brackets – the <input> and <output> sections. These match up to the column headers in the Examples table. This version works as written in the book.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s