Wednesday, August 24, 2011

HOWTO - Creating a resharper file template





I recently created a Resharper file template that simplifies for me the process of adding a new Test class in a test project and gets me directly to the point where I can start writing the test [without doing any of the boiler plate stuff]. Here is a simple DIY manual for creating a Resharper file template. This is essentially a template for creating a nunit test fixture.
We notice that there are redundant actions that you have to perform every time we want to add a new test class to our project. I therefore want to have a template that does all the plumbing work for me whenever I want to create a new test.

Click on the "Resharper -> File Templates" menu in Visual Studio.
Select the "File Templates" tab in the window that appears and click on the +Add Button
Resharper next displays a create new template window. 

In the Description, add a name for the template(I admit this is oddly named). And in the text area to the bottom left, add the content that you want your template to fill out for you automatically. My template looks like this. 

 Notice the identifier(the rich tokens surrounded by the $s) and the replacing macros to the right of the template body. Resharper allows you to choose the macro that you want simply if you click on the 
Change macro... link. Choose the one that makes most sense to you. 






No comments: