I just learned to use ReSharper’s code snippet feature, called Live Templates. I was looking for a code snippet to generate an NUnit test method. Oddly, despite ReSharper’s support for running NUnit tests, they didn’t see fit to include an NUnit test snippet. (Instead they included templates for the xUnit framework [Fact] and [Theory] methods, so I guess we know what framework they’re using.) So, I just created my own. Here’s how:
Step 1: Open ReSharper’s Live Templates dialog from the ReSharper menu in Visual Studio.
Step 2: Navigate to the folder where you’d like to add a Live Template and click the New Template button: (For me, this was the C# folder under the User Templates folder.)
(ALT+PrtScn didn’t capture the mouse pointer, but you get the idea.)
Step 4: Save your new Live Template and turn it on by selecting the checkbox next to it in the Templates Explorer dialog.
(Again, ALT+PrtScn didn’t capture the mouse pointer, but you get the idea.)
So, now, assuming I’m using ReSharper’s IntelliSense (to check go to ReSharper / Options / IntelliSense / General), I can create a test simply by typing “te” and selecting my Live Template from IntelliSense.
Sure, you could do all of this in Visual Studio, without ReSharper. In fact, Visual Studio 2010 includes a code snippet to generate tests in their syntax (where [Test] becomes [TestMethod]). But, you would have had to hand edit the snippet XML. Plus, ReSharper also includes Surround Templates (i.e. “surround the selected code in an if/for/try statement, please”) and File Templates (to create that new Test Fixture classes with all the correct NUnit using clause and [TestFixture] statement, for example).
To paraphrase Red Green: If your peers don’t find you handsome, they should at least find you handy.