Testcop - a Resharper plugin to help with unit tests
Overview
TestCop is a
resharper plugin that helps when working with unit tests. This plugin is designed for use with mstest &
nunit but should work with any other unittest framework that requires you to assign a test attribute (e.g.
TestFixture) to your unit test classes and/or methods. It has a number of resharper inspections that help ensure healthy test projects that follow an approach I've been using for a number of years where each code assembly has an associated test assembly.
Testing and how to write tests are a very personal thing...this is something I've developed in my spare time and found useful enough to share with the wider community...it won't suit every project/solution/individual.
Toggle between code and test
The plugin provides a
keyboard shortcut (ctrl-g,ctrl-t) to switch between code and test files (the reason why I originally wrote the plugin). It uses the name of the test file to identify the name of the class under test and when toggling between code and test it can optionally look for usages within the test assembly. If the class file/test is missing it will offer to create it in the correct location.

And a number of Resharper highlightings to help with writing and maintaining tests within larger solutions.
Highlightings
- Methods using the test attribute must be public
- The class name within the test file name doesn't exist in a nontest project
- The class name within the test file name exists but is in a different assembly to the one expected
- The class name within the test file name doesn't match the test class
Usage
To be able to use this plugin you need to configure your solutions in the following way..
1. Test classes must end in the name
Tests (configurable)
2. Test are held in assemblies separate to the assembly under test. Each test assembly should correspond to one assembly under test.
3. Assemblies containing tests must have a namespace (not necessariliy file name) that ends in
.Tests (configurable)
4. The file name containing the unit tests must contain the test class name inline with the following rules
- The file named
MyClassTests.cs would contain the class
MyClassTests testing
MyClass - The file named
MyClass.SomeCategoryTests.cs would contain the class
MyClassSomeCategoryTests testing
MyClass (this enables you to split up your unit tests into categories e.g. MyClass.SecurityTests.cs
5. The first part of the test filename (see point 4) must relate to a class within the associated code assembly. This helps ensure renames of code are reflected within the test classes. The only exceptions are BDD style class names which begin typically with
Given or
When (configurable).
TestCop Installation R#7.1
Installation is via a simple batch file that copies the DLL to %AppData%\JetBrains\ReSharper\v7.1\Plugins\TestCop if you prefer to manually deploy follow the instructions at
http://confluence.jetbrains.net/display/ReSharper/1.5+DeploymentNote: TestCop will register
keyboard shortcut Ctrl-G,Ctrl-T (go test) - you may need to re-assign any conflicting shortcuts.
TestCop Installation R#8.0
Installation is via the Resharper -> Extensions Manager menu item. Very easy to use.
https://resharper-plugins.jetbrains.com/
Feedback
yahoo.co.uk email account for feedback is
resharper.testcop