Earlier this week I saw this question on Stack Overflow asking if it was possible to run MS Team System Tests under NUnit. At first, this sounds like a really odd request. After all, why not just convert your tests to NUnit and be done with it?
I can think of a few examples where you may need interoperability – for example, two teams collaborating where team #1 has corporate policy for MSTest, while team #2 doesn’t have access to a version of Visual Studio with Team System. Being able to target one platform but have the tests run in either environment is desirable. Whatever the reason, it’s an interesting code challenge.
Fortunately, the good folks at Exact Magic Software published an NUnit addin that can adapt Team System test fixtures to NUnit. Since NUnit identifies candidate fixtures simply by examining attribute names, the addin’s job is fairly straight forward, but it also recognizes MS specific features such as TestContext and DataSource driven tests.
Unfortunately, the NUnit adapter uses features that reside within the nunit.core assembly which ties it to a specific version of NUnit. In this case, the addin will only work with NUnit 2.4.6. This is a frustrating design problem that plagues many NUnit addins, including my own open source project.
Note: NUnit 3.0 plans to solve this problem by moving the boundary between framework and test runner so that each version of the framework knows how to run it’s own tests. The GUI or host application will be able to load and execute the tests in a version independent manner. Hopefully this means that addins will target and execute within a specific framework version, but will work in different versions of the user-interface.
The current version of NUnit (2.5.2) is a stepping stone between the 2.4.x framework and the upcoming overhauled 3.0 version. As part of this transition, there’s a lot of breaking changes between older versions. For me, this translates into a problem where Exact Magic’s project simply won’t compile if you update the dependencies. Since I need to do similar work for my own project, this was good exercise.
I’ve reworked their code and put it here.
A few known caveats:
- The unit tests for the adapter attempt to perform reflection calls to internals fields or methods within the NUnit.Core that have been renamed or no longer exist. I haven’t bothered fixing these tests.
- Does not appear to have support for AssemblyInitialize or AssemblyCleanup, though these could be adapted by adding an EventListener when the test run start and finish. I may add this feature.
- The adapter doesn’t wrap functionality contained within MS Test, it simulates it’s behavior. While it has the same result, it won’t capture the exact same nuances of Microsoft’s implementation.
If you have any concerns or questions, let me know.