Code Design
Courses and Workshops on Effective Code Design

ReSharper Templates for Unit Tests

I am sharing here my resharper templates that I use. You should be able to easily import them.

The most useful one is the TestMethod template:

[TestMethod]  
public void MethodUnderTest_Scenario_ExpectedBehaviour()  
{
     Assert.Fail("Not yet implemented");  
}

It follows the unit test naming convention proposed by Roy Osherove in his book “The Art Of Unit Testing”. Naming your unit tests like this it helps you in writing good unit tests, because it foces you to keep your tests simple and test only one thing. If you cannot name the test method like this either you’re testing more than one thing, either your test is too complex, so you cannot name the test scenario. If you’re in the last case consider to refactor your production code.

Another great advantage I’ve found by following Roy’s convention is that I can easily know, just by looking at the test run report, where the bug is when a test fails. This way I reduce my debug time to almost zero for the code under unit tests and this gives me a higher efficiency.


You've successfully subscribed to Code Design
Great! Next, complete checkout to get full access to all premium content.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Error! Billing info update failed.