Marc Duiker

My experiences & thoughts about Azure, DevOps & personal programming projects.


Visual Studio Snippets for Unit Test Methods

NUnit test snippet

Unit Test Method Naming

As mentioned in a previous post, having a clear naming convention for unit test methods is important to keep tests readable and maintainable. Sticking to the convention might be difficult at first and require some discipline but is definitely worth it in the long run.

Visual Studio Snippets

In order to make it easy for myself (and other developers) to use the <UnitOfWork> _ <StateUnderTest> _ <ExpectedBehaviour> naming convention, I’ve created two code snippets, one for NUnit and one for MSTest. After importing the snippets (see below) you can use the them by typing:

nutest[TAB] (for NUnit)

or

mstest[TAB] (for MSTest)

The resulting code is displayed at the top of this post. The snippets use three placeholders (marked in yellow) which make up the method name using the suggested convention. In addition I’ve added Arrange, Act, Assert comments in order to help structuring the test.


The Importance of Good Unit Tests and Test Reviews

GOTO by xkcd

I’m currently following an online TDD course by Roy Osherove. I’m about half way through and although I have quite a bit of experience writing unit tests and using test frameworks I’ve gained a lot of knowledge from the course already. Here are some highlights about good unit tests and test reviews.

Good Unit Tests

Roy stresses the importance of the three pillars of a good unit test:

  1. Readability
  2. Maintainability
  3. Trustworthiness

If any of these are not taken into account during development developers are likely to drop unit tests all together because it will become a burden to use instead of an aid.



Marc Duiker profile

Marc Duiker

Lead Consultant @ Xpirit

Twitter || LinkedIn || Github