My colleague, Joe Ocampo, created a ReSharper template:
To add the template, go to ReSharper->Options in the menu:
Then choose “Live Templates” underneath the Templates heading from the items on the left of the popup window. Under the “User Templates” section create a new template called “test” with the text above:
When you write your unit test fixture with the “Given, When, Should” format, these items come in handy. Once you get ready to write your test, you can just type the word “test”, then press tab and get the following in Visual Studio:
Ignore the red underlines and why the “TestName” word is on the next line. The red lines will disappear after all of this is complete and the new line is necessary for the Visual Studio macro we’re about to create (so it can parse your test method name correctly).
You have to add a macro to Visual Studio via the Tools->Macros->Macros Explorer menu option (or use Alt+F8):
This will open the macros window. Right-click “MyMacros” and choose “New Module”:
Name the module TestMethodNameFormatterForBDD (or whatever you want to call it):
This will add it back to the Macros window. Double-click the new macro or right-click and choose “Edit”. This will open the Microsoft Visual Studio Macros (MVSM) IDE. Select all and replace the text with the following:
Should look like this:
Choose File->Save and then close the MVSM window. Back at Visual Studio choose Tools->Options and go to the keyboard option on the left of the popup. In the “Show commands containing:” TextBox, type “BDD” and your new Macro should show in the list. I personally like the Ctrl+` (tick – to the left of the number 1 on the keyboard) for my keyboard assignment, but choose whatever you like. Just type that choice into the “Press shortcut keys:” TextBox and click the Assign button.
Now when you type your “test” keyword that triggers the ReSharper template, just type out the test name with spaces:
Your cursor will be at the end of the word “selected”. Press your keyboard command, mine being Ctrl+`. The macro will kick-in and you will see your spaces replaced with underscores and your method name moved up to the same line as the public void declaration.
Post Footer automatically generated by Add Post Footer Plugin for wordpress.