Los Techies : Blogs about software and anything tech!

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.

Kick It on DotNetKicks.com
Posted Mar 19 2009, 12:57 PM by derick.bailey

Comments

DotNetShoutout wrote My Current BDD / SpecUnit Live Templates - Derick Bailey
on 03-19-2009 5:11 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Webmaster Crap » Blog Archive » My Current BDD / SpecUnit Live Templates - new ThoughtStream … wrote Webmaster Crap » Blog Archive » My Current BDD / SpecUnit Live Templates - new ThoughtStream …
on 03-19-2009 7:02 PM

Pingback from  Webmaster Crap  » Blog Archive   » My Current BDD / SpecUnit Live Templates - new ThoughtStream …

Scott Bellware wrote re: My Current BDD / SpecUnit Live Templates
on 03-30-2009 5:58 PM

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

derick.bailey wrote re: My Current BDD / SpecUnit Live Templates
on 03-30-2009 6:03 PM

@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.

Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems