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:

image

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.

image

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:

image

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:

image

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:

image


Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs SignalLeaf.com - the amazingly awesome podcast audio hosting service that everyone should be using, and WatchMeCode.net where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in .NET, Agile, Behavior Driven Development, Continuous Integration, Resharper, Unit Testing. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.lostechies.com/members/bogardj/default.aspx bogardj

    I even go one step further – all specs in a for a given concern in one file. I’ve even tried it as far as “spec file per feature”. Then nested classes group specific concerns, down to the lowest level. The cool thing is that “Ctrl+N” works for nested classes – so I can have specs for a type spread across multiple different concerns, each with their own aspects for that feature located within the feature where it was relevant.

    I haven’t done it a whole lot, but it’s kinda neat to see why some piece of code is important.

  • http://neilmosafi.blogspot.com Neil Mosafi

    Can’t you just do Ctrl+Shift+N to search based on filename, for ValidationSpecs.cs

  • http://www.lostechies.com/members/derick.bailey/default.aspx derick.bailey

    @Neil – true, you can search by file names. that does help a lot, but i sometimes end up with multiple classes in one file.

  • http://www.lostechies.com/members/bogardj/default.aspx bogardj

    @Neil

    Plus, nested classes are much more powerful in Ctrl+N – nested namespaces are pretty much hidden to R#.

  • http://weblogas.asp.net/jvano joey

    Yea, I do the same. I think I first heard this from JP Boodhoo’s blog.