My Current BDD / SpecUnit Live Templates

UPDATE 3-30-2009: FYI, I’ve made a few minor updates to my templates. They are now a little more intelligent – the “spec” templates automatically inherits from the parent spec file’s superclass, and all of the templates now have more intelligent placing of cursors for the “When” and “Should” text. I’ve also updated the “When” and “Should” variables to default to a blank (empty) state, so you can start typing without any existing text highlighted by the cursor. All of the “constant value” macros below are defaulted to nothing (empty). The zip file linked at the bottom has been updated with these changes.

 

—————————————————

I use Resharper’s Live Templates every day for my BDD / SpecUnit tests and I find them quite useful, so I thought I would share with the world.

File Tempate: “Specification Tests”

Builds a new context/specification file based on the supplied name. Builds a super-class that inherits from ContextSpecification and has an empty SharedContext, named based on the file name supplied. Builds a complete specification class with an empty context and one empty observation, inheriting from the super-class.

The template:

using NUnit.Framework;
using SpecUnit;
 
namespace $NAMESPACE$
{
   public class $FILENAME$
   {
 
       public class $FILENAME$Context: ContextSpecification
       {
       
           protected override void SharedContext()
           {
               
           }
       
       }
 
       [TestFixture]
       [Concern("$CONCERN$")]
       public class When_$WHEN$ : $FILENAME$Context
       {
   
           protected override void Context()
           {
   
           }
   
           [Test]
           [Observation]
           public void Should_$SHOULD$()
           {
               $END$
           }
   
       }
 
   }
}

The variable options:

image

Live Template: “spec”

Builds a complete specification class with an empty context and one empty observation.

The template:

[TestFixture]
[Concern("$Concern$")]
public class When_$When$: $CONTEXTNAME$Context
{
 
   protected override void Context()
   {
       
   }
 
   [Test]
   [Observation]
   public void Should_$Should$()
   {
       $END$
   }
 
}

The variable options:

image

Live Template: “obs”

Builds an empty observation

The Template:

[Test]
[Observation]
public void Should_$Should$()
{
   $END$
}

The variable options:

image

Exported Template Package

If you want to import these templates, I have an export of my BDD/SpecUnit templates from Resharper at the link below. These XML files can be directly imported into Resharper’s Live Templates and will have all of the above templates and options automatically set.

You can download the template package (2 .xml files in a .zip file) here.


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, Behavior Driven Development, C#, Resharper, Unit Testing. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://scottbellware.com Scott Bellware

    You know… I’ve heard that even the guy who wrote the SpecUnit stuff uses mSpec now :)

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

    @scott,

    LOL! :)

    I don’t like mspec’s syntax noise… all that static crotch operator stuff bugs the crap out of me when trying to read it.

    specunit meets my needs – and when it doesn’t has an assert that I want, i have the default functionality of nunit to fall back on.