# Monday, 16 April 2012

Back in 2009 I published ReSharper Live Template For Creating Unit Test Stub.  A lot of things have changed since 2009, including my templates.  Since I am doing another series of presentations on Test Driven Development I thought I should get these out because people always ask for them.

As stated in my original post these templates are a way for you to create unit test names that help in describing the true intentions of the test and also to provide a common unit test format that will make reading and comprehending your unit tests easier on everyone.  And of course as lazy developers any redundancies should be automated!

The first template is for a unit test that does not have specific input criteria.

Test w/out Input Criteria
  1. [TestMethod]
  2. public void $MethodUnderTest$_Should_$ExpectedResult$() {
  3.     //Arrange
  4.     $END$
  5.     //Act
  6.     //Assert
  7. }

The second template is for a unit test that has specific input criteria.

Test with Input Criteria
  1. [TestMethod]
  2. public void $MethodUnderTest$_Should_$ExpectedResult$_When_$Condition$() {
  3.     //Arrange
  4.     $END$
  5.     //Act
  6.     //Assert
  7. }

You can take the two templates and create new Live Templates and map to whatever key stroke combination you wish.  I use ‘tt’ and ‘tw’.

Note:  I have been using these Live Templates since ReSharper 3 and I am currently using them in the latest build of ReSharper 6 without any issues so you should be good to go.

As always if you feel these can be improved on or have other Live Templates you want to share let me know in the comments below.

Monday, 30 December 2013 08:50:58 (Central Standard Time, UTC-06:00)
Guarantees, The ideal one unique.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview