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$
           }
   
       }
 
   }
}
</p>

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$
   }
 
}
</p>

The variable options:

image

Live Template: “obs”

Builds an empty observation

The Template:

[Test]
[Observation]
public void Should_$Should$()
{
   $END$
}
</p>

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.

It’s All About The Benjamins, Baby.