Tuesday, August 16, 2011

Resharper FileTemplates FTW!!





Sometimes, when you are pairing you feel the need to be more precise in the way you write code. You might want to generate the same amount of code using lesser keystrokes. This has a few un-obvious advantages:
  • that your pair is not going to have to sit bored as you keep pecking on that keyboard
  • with lesser keystrokes, you’re going to write code quicker(duh),
  • with lesser keystrokes, you have fewer errors.
  • You look cooler and more sophisticated.




Even the fastest typists I know are like hulk when it comes to coding - All brawn(Like Hulk). Coding is not just typing. Its more sophisticated(Like Flash).


Normally, creating a test class in c# would involve the following steps.

  1. Navigating to the folder where you want to put your test file.
  2. RightClicking on the folder and clicking add -> Class
  3. Giving a proper name for the test class.

  4. Adding a using NUnit.Framework; line of code at the top of the file
  5. Marking the class as [TestFixture]
  6. Adding [SetUp] and [TearDown] methods
  7. Finally, you get to the test and get to the arrange, act, assert tradition.
One such feature in Resharper is File Templates and its darn useful.

To illustrate, lets try writing a basic Test Class with a basic test and see how many steps it takes.


Alt+Insert on a folder and selecting Test
 




Giving the new Test Fixture a proper name

Voilla


2 comments:

MOTO said...

A small suggestion to u. The name of your blog and ur recent posts does not merge together. Change the name

Prasanth Guruprasad said...

thanks for the tip moto. This is just a staging area and I intend to do a big overhaul sometime next week. Ill be moving this to wordpress because of the developer api comfort available.