I am trying to understand when should you test via BDD such as cucumber/specflow, and when should you test your gui directly.
For example, the test “the AdminHelp button should only be seen by an administrator”.
This admin button is on a particular page. Should I test it in a BDD fashion (i.e. the scenario where:
- When an Admin Logs in
- Then he sees the AdminHelp button
or
write a unit test that sets current_user to an admin user, and test whether the html rendered by the template includes AdminHelp button or not.
Thanks.
Specflow is an automation tool, but it works on a higher level than, say, Selenium or Microsoft UI Automation. You would normally use it to describe a scenario in which a user uses the application. For instance:
Notice that I haven’t mentioned the admin help button anywhere in there. Andy could quite easily have asked a secretary for help! We’re describing the steps declaratively, in terms of the capabilities provided by the system. This is the style of BDD.
Specflow then maps the Given, When and Then phrases to code steps. In the code, you can use automation tools to actually click the button. However, it’s far more maintainable to use the same language that the business use to describe the system’s capabilities; because then, if the UI changes, you only need to change 1 step and not 15-odd scenarios.
Also, using the higher-level language in the scenarios tends to keep the business interested, which means it’s much easier to have conversations with them about those scenarios. Conversations are at the heart of BDD, and I suggest starting there, before worrying about how to do the automation part.