As I said in my previous post I preferred using tools (StoryQ and NetSpec) to using descriptive method names (those with long names containing lots of underscores). Well, I lied. At first I was convinced that the tools would be good enough for me but as it usually occurs the truth lies somewhere in between.
Here's what I have in mind.
Let's take as an example the famous sample showing how you could apply BDD when you want to develop the logic for transferring money from a savings account to a cash account. If you use StoryQ you could end up having something like this:
But what if we add more scenarios to this story:
Well, it becomes quite a bloated piece of code. We could refactor it and move the behaviors in different methods:
It's better but still it's not perfect and maybe you've noticed the duplication of the scenarios' descriptions. First in the methods' names and second when creating the scenario but in a plain text format. We also have the same duplication for the story name. If you create several user stories you'll notice that you'll repetitively do the same things - instantiate a user story, assert it at the end, etc. How we could possibly optimize this? Of course with a base class:
Then you could inherit from this class and your stories could look like the following:
And here's the output from the test runner:
To make your life even easier I'm attaching an item template for a user story class. You should just copy the .zip file to "C:\Users\[USER]\Documents\Visual Studio 2008\Templates\ItemTemplates". Then when you want to add a new item to the project (CTRL + Shift + A) you'll be able to select the "User Story" template:
I'm also attaching a code snippet for creating easier a new scenario. From the Tools menu (Visual Studio) select "Code Snippets Manager", then "Import" and select the snippet file. Then when you type "scenario" somewhere in your test class and press TAB, you'll get the code for creating a new scenario:
I hope this information will help you author user stories easier if you decide to try BDD.
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.