Profile picture Schedule a Meeting
c a n d l a n d . n e t

Unit Test Live Templates for ReSharper

Dusty Candland | |

Attached are Live templates that can be imported into ReSharper to help with writing unit tests. There are templates for Test, Setup, TearDown, TestFixtureSetUp and TestFixtureTearDown methods.

I find that failing test cases are really good reminders of things that need to get done, so often I will add test methods with Assert.Fail(); as the body, usually the method name is enough detail for me to remember what needs to be done.

Lastly, I’ve started using the ConditionalAttribute on my test class methods so they won’t be compiled in release mode. If this is not your style you may want to modify the templates.

ReSharperUnitTestLiveTemplates.xml (2.63 KB)

**Update: ** I’ve decided against using the ConditionalAttribute in favor of adding compiler directives to the test files. I quickly found that not using the attribute became a source for failing tests that shouldn’t have been run and/or simple code leaks. I know that many people prefer a different class library for tests, but I think that only makes sense for non unit tests. Anyway, here’s the updated file.

ReSharperUnitTestLiveTemplates1.xml (2.48 KB)

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: