December 2, 2008

Visual Studio vs. NUnit unit tests

I've used NUnit over the last few years at a few jobs to do unit testing in C# code. At my current job we started trying to use the unit test features of Visual Studio 2008. We had been using NUnit but we needed a solution that would work with our new C# code, as well as testing our existing legacy C++ code. The C++ code we have is primarily unmanaged cross platform code that is used in both Windows and Linux applications.

Everything we had read indicated that the Visual Studio unit testing didn't work very well with unmanaged code. At first this seemed true, but we have been able to work around this well enough by just simply setting project settings to allow executing mixed mode code.

One of the biggest issues has been trying to debug into unit tests that are throwing exceptions. Because the unit tests are managed code, and most of the code being tested is unmanged, almost all of the exceptions come across as SEHExceptions. This can make it more difficult to determine what is going on, but can be overcome by going to Debug->Exceptions and checking some of the exceptions to break the code when the exceptions are thrown.

Other than that, the biggest concerns I've had with the Visual Studio unit test system is that they seem to have been over-engineered (Microsoft would never do that, right?). Pretty much everything seems to have been copied from NUnit, except it is harder to use. Just trying to determine how to run a specific test or tests is a pain. NUnit is just very simple and easy to use.

So far everything is working OK, and at least we have one solution that works for both C# and unmanaged c++ unit tests, but I still miss the ease and simplicity of NUnit.

[Update: 2/6/2009]
We decided to use Visual Studio unit test for C++, but after more debate decided that NUnit is a far superior solution. It just works and it works well. Visual Studio works, but not as well and not as easily.