Over the past few months, I’ve been doing test-driven development (TDD) using VstsUnit (aka MSTest), which ships with Visual Studio Team System. (A client’s choice to use VstsUnit, not mine.) I’m an avid ReSharper user and quite like their unit test runner, which allows you to run NUnit or csUnit tests directly from within Visual Studio. Unfortunately it doesn’t support VstsUnit. When Albert Weinert released MbUnit support for ReSharper a few months back, I realized that JetBrains had an undocumented plugin model for their unit test runner and I could integrate support for VstsUnit into ReSharper. Without further ado, I present to you the VstsUnit Plugin for ReSharper.
VstsUnit Plugin for ReSharper
Out of the box, JetBrains ReSharper Unit Test Runner supports NUnit and csUnit. This ReSharper plugin adds support for the Unit Testing Framework in Visual Studio Team System (VstsUnit), also known as MSTest.
N.B. The plugin will likely work with JetBrains UnitRun, but I have not taken the time to test it with UnitRun. Unfortunately you cannot have ReSharper and UnitRun installed at the same time, which means I need to set up a virtual machine with Visual Studio 2005 and JetBrains UnitRun. I have not taken the time to do this yet.
Installation
- Close Visual Studio 2005.
- Extract the contents of archive, including the VstsUnit folder, to:
%ProgramFiles%\JetBrains\ReSharper\VS2005\Plugins - Launch Visual Studio 2005.
- Open a project containing VstsUnit tests.
- Open a test file containing a TestClass with TestMethods. Standard ReSharper icons will appear in the left margin and allow you to run the unit tests.
Known Issues
- ReSharper Unit Test Runner icons do not appear beside TestClass and TestMethod.
- This is typically caused by having an assembly reference to another unit test framework. ReSharper Unit Test Runner (and UnitRun) only support a single unit test framework per test assembly. Remove references to NUnit.Framework, csUnit, and/or MbUnit.Framework from the References in your test project. This is a known limitation in the JetBrains’ current unit test runner implementation. A plugin votes on whether the current assembly contains tests that it can run. If the plugin votes “yes”, the unit test runner stops querying additional plugins. NUnit and csUnit get queried before third-party plugins.
- Poor performance when running full test suite.
- Unit tests are run by invoking mstest.exe and parsing the resulting XML file (.trx). The Unit Test Runner invokes the plugin once for every TestClass (aka TestFixture in NUnit terms). Unfortunately MSTest has high overhead as it copies all files to a new directory to execute tests. There is no way to turn off this behaviour in MSTest. It may be possible to run the full suite of tests and cache the results, but there are numerous problems with this approach including determining whether the cache is fresh and keeping TestClass or TestMethod runs responsive. Due to the architecture of MSTest, it is not possible (without what would likely be some truly awful System.Reflection work) to run the unit tests in-process as is done for NUnit and csUnit.
- Cannot debug or profile VstsUnit tests.
- I have not found a way to hook the debugger or profiler to the MSTest process. Hopefully this will be possible in a future version.