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:

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.

This entry was posted in Unit Testing. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s