Title: The Cucumber Book – Behaviour-Driven Development for Testers and Developers
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.