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.

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$

{

publicclass $FILENAME$

{

publicclass $FILENAME$Context: ContextSpecification

{

protectedoverridevoid SharedContext()

{

}

}

[TestFixture]

[Concern("$CONCERN$")]

publicclass When_$WHEN$ : $FILENAME$Context

{

protectedoverridevoid Context()

{

}

[Test]

[Observation]

publicvoid Should_$SHOULD$()

{

$END$

}

}

}

}

The variable options:

Live Template: “spec”

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

The template:

[TestFixture]

[Concern("$Concern$")]

publicclass When_$When$: $CONTEXTNAME$Context

{

protectedoverridevoid Context()

{

}

[Test]

[Observation]

publicvoid Should_$Should$()

{

$END$

}

}

The variable options:

Live Template: “obs”

Builds an empty observation

The Template:

[Test]

[Observation]

publicvoid Should_$Should$()

{

$END$

}

The variable options:

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.