Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you counter BDD-scripting anti-pattern in Specflow?

Tags:

specflow

This is an example of one of our acceptance tests:

Feature: Add an effect to a level
In order to create a configuration 
As a user
I want to be able to add effects to a level

Scenario: Add a new valve effect to a level
Given I have created a level named LEVEL123 with description fooDescription
And I am on the configuration page
When I click LEVEL123 in the level tree
And I expand the panel named Editor Panel
And I click the Add Valve Effect button
And the popup named ASRAddVal appears
And I click the Add new button
And I fill in these vertical fields
     | field name  | value                |
     | Name        | Effect123            |
Then I should see the following texts on the screen
     | text                     |
     | Effect added : EFFECT123 |

We feel that this is getting a bit to verbose and we want to hear how you reduce steps in Specflow. From what I've read so far, creating specific non-reusable steps is not recommended, so what is considered "best practice" when doing this in SpecFlow?

Update:

What I am trying to say is that I've learned that you should try to create generic steps in order to re-use them across multiple tests. One way to do that is to parametrize your steps, for example: "Given I have created a level named ..", but the parameterization also introduces verbosity. I want to end up with something like Bryan Oakley suggests in his answer, but I just can't see how I can do that without creating steps which are very specific to each tests. This again means that I'll end up with a lot of steps which reduces maintainability. I looks like SpecFlow has some way of defining abbreviating steps by creating a file which inherits a base class called "Steps", but this still introduces new steps.

So to summarize things; show me a good approach for ending up with Bryan Oakleys answer which is maintainable.

like image 226
Marius Avatar asked Aug 04 '11 08:08

Marius


1 Answers

I would simplify it to something like this:

Scenario: Add a new valve effect to a level
Given I have created a new level
When I add a new valve effect with the following values
     | field name  | value                |
     | Name        | Effect123            |
Then I should get an on-screen confirmation that says "Effect added: Effect123"

The way I approached the problem was to imagine that you are completely redesigning the user interface. Would the test still be usable? For example, the test should work even if there is no "Add" button in the redesign, or you no longer user a popup window.

like image 169
Bryan Oakley Avatar answered Jan 02 '23 23:01

Bryan Oakley