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

Ice cream by the scoop: An environmental mess

Photo of ice cream cone dropped on the pavement
“Tragedy” by Johnathan Nightingale (Flickr)

One of the happy side-effects of living in the Cities this summer is that I’ve been able to partake of locally made ice cream being sold by a number of local vendors. Morris doesn’t have a lot of options in that department (DQ isn’t really ice cream), so my ice cream habit is supported primarily by Ben & Jerry’s and Häagen-Dazs from Willie’s). Here in the Cities, however, there’s ice cream all over the place, and I’ve definitely been taking full advantage :)

In the process, however, I’ve been forced to confront the unfortunate reality of the packaging mess that is by-the-scoop ice cream. I always try to order it in cones instead of cups, so the container is consumed instead of entering the garbage stream, but even that’s often not a huge help. The Wilde Roast is just down the road a piece and has a nice selection of gelato, for example, and I have been known to amble down to enjoy a little. Unfortunately, even if I order a cone, they scoop it into one of their plastic serving cups (essentially as a measuring device), then splooch it into the cone, and then throw the cup away! They also stick a little plastic spoon in my cone, thereby ensuring that I’ve ended up putting just as much plastic crap in the waste stream as I would have if I’d ordered it in a cup in the first place. And then there’s the paper wrapper on the cone, and the napkins ’cause is runs and drips, and blah, and blah, and blah…

There was once this crazy time when people sat down and ate ice cream in a glass bowl with a metal spoon, both of which could be washed. This is simply not an option at the majority of the places I’ve been getting ice cream at – even if you sit down you get a paper or a plastic cup and a plastic spoon. And I seem to remember that when I was a kid ice cream cones were a more straight forward, less wasteful deal – there was probably a lot of paper (’cause they were still a mess), but there was a heck of a lot less plastic (like, I’m thinking, none).

This, frankly, is dumb, and we can totally do better. I suspect the big problem is that plastic is too cheap due to the complex subsidy chain, so neither the cost of its production or its disposal are being properly assessed in our accounting and decision making.

In the meantime, it would be nice if I could order my ice cream in a nice (or, hell, a cheap) glass bowl with a metal spoon. Maybe I should start bringing my own, although I suspect they’d refuse to scoop into it (some sort of health regs) and I’d still end up with a plastic spoon stuck on top before I’d managed to cut them off at the pass.

There’s an Izzy’s Ice Cream opening tomorrow about a block from the Guthrie, which is just across the river from where I’m staying. It’s a very good thing (for my waistline, my pocketbook, and for the environment) that it and I won’t be together very long before I head back to Morris.

A very good thing.

Related posts