Organizing BDD Context/Specs For Findability
Finding Classes With Resharper
It’s no secret that I’m a huge fan of Resharper. It rocks. I don’t like to code without it. One of the many features that I love is the Ctl-N shortcut to find a class. Resharper gives you this handy-dandy little search box:
What I really love about this box is the ability to not know the entire class name when searching. If I know my class involves the word “Super” and “Sexy”, I can type the letters “SS” and the search box will pull up any class with matching uppercase letters.
The same holds true for lowercase letters. I can do “SupSeV” and get results just matching those Upper/lower combinations.
BDD Context Specifications Have Long Strange Names
It’s also no secret that I’m a fan of BDD and Context/Specifications. I love the language oriented nature of context specifications and how it’s easy for me to see what the behavior of the system is supposed to be, in any given context. I’ve been using BDD style syntax for many months now, and have amassed quite a collection of Context/Specification tests in my current code – especially with 4 other developers using BDD syntax. After having done several hundred tests in this manner, I’ve found that there is a pretty significant disconnect between how I use SpecUnit.NET and how Resharper’s class finder works – the names of my specification classes. Look at this specification class name for example:
How am I supposed to search for this class name? I can’t remember all those words, none of them are capitalized, and all those underscores are probably going to throw Resharper off in my search string.
Organizing Context/Specification Classes By Parent Class/File Name
To combat this problem, what I’ve started doing recently is throwing in the use of a parent specification class with the same name as the specification file that I’m working in. Since our team has standardized on the “Specs” suffix for all of our BDD tests, I know that a file name of “ValidationSpecs.cs” will have a class called “ValidationSpecs”. In the file itself, my specs will be subclasses, like this:
With the file name ValidationSpecs and the parent class ValidationSpecs, I now have much fewer words to remember and a much greater chance that I’ll be able to use Resharper’s class finder feature. All I need to know that I’m looking for the tests that deal with validation, so by our naming convention, I can type in “VS” or “ValSpecs” and get the list back that I want: