Cucumber, et al, do have a role, me thinks

While there may be issues with how acceptance testing/behavior driven development tools like Cucumber have developed and been used, I continue to find them very useful, especially in circumstances where it’s important to decouple the tests from the design of the solution.

Uncle Bob just posted a nice piece about how Cucumber and other Acceptance Testing and BDD (Behavior Driven Development) tools (e.g., Fit) are in important ways a failed experiment. A short (and probably not complete) version of the argument is something like:

  • A key goal of these tools was to allow the business side of the house to write acceptance tests, or at least be able to read acceptance tests and agree that they are reasonably accurate and complete.
  • That mostly didn’t happen.
  • The tools became increasingly programmer centric, making it even less likely to ever happen.
  • This ultimately leads to developers having to support two test streams, acceptance tests and unit tests.
  • Developers ain’t keen, so they tend to drop one.
  • The one they drop is usually unit tests, which Uncle Bob strongly believes is the wrong one.

I can totally follow this train and see where this can lead to Bad Things. That said, however, I must say that I’ve found tools like Cucumber, Aruba, and Geb very useful in my university classes.

In the simple case, tools like Cucumber and Aruba often great for writing executable specifications for class projects. This is somewhat similar to the goal of having the business team write the tests, but obviously I’m in the fortunate position of being a developer as well as the person writing the specs. It’s very nice for teaching, though, because I can specify what I want them to do without over-specifying how they do it. Unit tests will typically need to reflect all sorts of design decisions, and part of the point is often for them to work through the design, so it’s nice to have tests that both they and I can use to sanity check their solutions without tying us all down to a particular set of design choices.

In the more complex case, our students have often found these tools to be extremely useful for their own tests, especially when they’re struggling with a new problem domain and/or a new set of languages, tools, libraries, etc. In many ways a unit test requires the ability to envisions at least some of the structure of the solution; you have to be able to see where a unit will be. If they’re writing their first web app from scratch, using languages and libraries they’re just learning, it can be really hard to know what the first test might look like. So they tend not to write it, instead doing “spikes” to try to understand how the pieces work. These “spikes” go on and on, get bigger and bigger, and often become the project instead of being thrown away, and none of that development was supported by any sort of tests.

While it can be really difficult to envision units in a totally new space, hopefully they can understand use cases and user behavior. Tools like Geb allow them to specify what the tool should do without (yet) understanding what the insides will look like.

In many ways the two cases are quite similar: A.T./BDD lets us write tests without committing to design decisions yet. In the first I don’t want to dictate those decisions, and in the second they simply don’t yet know what those will look like yet, but either way we get to specify what is hopefully some useful and significant behavior right away without getting bogged down in those issues.

In a perfect world, they’d start writing unit tests for key pieces of internal logic as the design develops, especially for units whose behavior is complex enough that it’s hard to catch all the combinations through the user interface. That doesn’t always happen, but eventually the instability of the UI often drives teams to bring some of the testing from the UI into more stable areas of the code.

So, do I think every project should start with Cucumber tests? No, definitely not. But I do think they’re damn useful in certain circumstances and I’m quite glad to have them.

Related posts

Such a gift: 24 years with WeatherGrrrl

One of Sue's cool art books
One of Sue’s cool art books

…a commodity has value and a gift does not. A gift has worth. – Lewis Hyde

Tomorrow (24 June) marks the 24th anniversary of our marriage!

There are so many things I’m grateful for, and no way to enumerate them or document them here, so I’ll settle for an example.

Among her many “strangely inventive” artistic talents, Sue makes books. Wonderful, handmade books, where she cuts and folds all the paper, sews together the signatures, builds the cover, and glues it all together. Some of these are displayed in galleries, while others (such as the one pictured here) are notebooks or journals filled with blank pages inviting us to share our thoughts in word or sketch.

For the past several years, Sue has made such journals as high school graduation gifts for our and, more substantially, Tom’s friends in that year’s graduating class. As he moves on to college, the numbers are beginning to contract, but over the years she’s made many dozens of these books, often for people we didn’t actually know terribly well. That’s a lot of work, constructing by hand an object whose future is far from certain. She is, after all, making blank books, in an age where the future of books is at best unclear, an age where most are far more likely to send a text message or post on a blog [I’M LOOKING AT ME!] than to write a letter or keep a journal on paper.

Thus these are, in the true sense that Hyde means in the opening quote, gifts. As handcrafted pieces of art, they have clear worth, but their value (and how they are valued by the recipients) is quite uncertain.

Yet she keeps making them. In a flurry of activity every May between the end of the University school year and the high school graduation she cuts and folds and glues and frets. She picks out different papers to use as covers, and has Tom give her feedback on which covers would make the most sense for which graduate. She increases the worth of the world (if not its value) through these gifts, each of which is in fact a multiple gift. It is obviously a gift to the graduate, but this effort is also a gift to our son, and a thank-you to the families of these students who have been important to him.

And, to the point of all this, these are also a gift to me. For while each of these books is made by her and is officially a gift from Thomas, her work enriches us all and the glow it casts as it goes out into the world reflects back on our whole family even if it was her hands that did all the sewing.

So I say “Thank You”, for this and the untold gifts large and small that she has shared with me. It has been a truly splendid 24 years together, and I look forward to many more decades to come!

With all my love,

     – Nic

Related posts