Stop Writing Scenarios That Test Everything Through The View

Following on from my last post, I wanted to mention a common anti-pattern that Kevin’s case against cucumber mentioned. Scenarios that are too focussed on the user interface. Scenarios written as an imperative set of instructions for a machine to follow.

Scenarios like this.

Given I go to the homepage
And I fill in my username
And I click sign in
When I click "Accounts"
Then I see "Current Account"
And I see "Savings Account"

sigh

There has been quite a lot written about this, the canonical post is from 2008. The cucumber team made a mistake including web_steps.rb - they were removed 2 years ago.

The problem here isn’t just isolated to the imperative style of this scenario, but also that the scenario is highly coupled to the view.

Testing through the view is something you have to be wary of with any tool. It’s slow and brittle. That isn’t to say it has no value, but you don’t need every test to go through the UI. Beware the ice cream cone anti-pattern.

I’ve written a little more about this here, Seb has introduced the Testing Iceberg and Matt talks more about it here.