VS2012 Code Snippet for Test Methods

I don’t post about unit testing, but when I do, lather, rinse, repeat.

Here’s a snippet to generate a AAA-friendly test method that can be invoked by typing aaa and then pressing tab. Better if you do it in a test class #JustSaying.  Tested in VS2012, works here Smile. The great thing about VS2012 – and to be honest I’m not sure what version this awesome was introduced – you can edit code snippets on the fly in Visual Studio and test them as you save them, without closing the file or having to restart Visual Studio.  Brilliant. I have been doing the VS restart for years, and just tripped over this feature.

Oh, right, the code snippet!

(View Gist on GitHub)

This snippet is based on Roy Osherove’s recommended test naming convention/theories. There’s no general consensus on what constitutes the “correct” test name, but this is pretty sound as far as conventions go.