http://msmspec.codeplex.com/

MSMSpec is a T4 based tool that can generate MSTest code to extend your MSpec (Machine.Specifications) tests so that they can run under anything that runs MSTest. This means all the Visual Studio testing features become available for your MSpec tests without the need for Resharper, TDD.NET or setting up an external tool. This can be useful in scenarios where you need to / require / are forced to use certain technologies.

Features

MSMSpec is a single T4 file that you can add to the root of a class library project that has a reference to Machine.Specifications.dll. The T4 template will scan through the project and identify classes that have MSpec components in them (It, Because, Establish, Cleanup, Ignore). It will mark such classes as partial and create a nested *.mstest.cs file adding a corresponding partial class. The corresponding class will have MSTest attributes on methods which will get called when MSTest runs. If you manually add the T4 file, I would recommend unloading and reloading the project (or simply closing and opening VS). This would enable the testing buttons in visual studio. MSMSpec should work with class hierarchies in tests.

Installing without NuGet

Make sure your project is a C# class library project and already has a reference to Machine.Specifications.dll. Then simply add MSMSpec.tt to the root of your project. Unload and reload the project (or close and open VS) to access the test buttons.

Installing via NuGet

PM> Install-Package MSMSpec

or simply search for MSMSpec using the NuGet GUI.

Unload and reload the project (or close and open VS) to access the test buttons.

Requirements

VS2010, C#, .NET 4.0 only for now.

Limitations

MSpec behaviours are not supported. They will be ignored in the current version (and I’m not personally a fan of MSpec behaviours – they result in having to jump around to see all that a test does). It should work with source control systems but hasn’t been fully tested with TFS (yet). Merc / git users should be fine.

Tips

1. Be sure to install the VS extension Chirpy (http://chirpy.codeplex.com/). This will allow you to run the T4 on every build automagically. This can help resolve many source control issues (for TFS) and also ensure you’re generating the latest MSTest stuff for your MSpec test before testing. With Chirpy installed, go to Tools > Options and set the following:

chirpy

Chirpy will not only auto run T4 files, it can help with css, allow less syntax, has a closure compiler etc.

2. The MSMSpec T4 generates a nested MSMSpec.cs file that has a TestExecutionHelper class in it. This class is used in the *.mstest.cs files to work around MSTest’s weird test execution order. If you have two test projects where one references the other, this might be a problem as both projects may have this file. In this case, simply open up one MSMSpec.tt file and find the line (near the top):

const bool ShouldGenerateHelper = true;

Set that flag to false and the helper won’t get generated.

Show me ze codez

You can find MSMSpec at http://msmspec.codeplex.com/ – if you think you can improve it, please feel free to do so.

Enjoy!