Difference Between NUnit and Visual Studio Team System Unit Testing Framework

While converting a project from VS.NET 2003 to Visual Studio 2005, I also converted the unit tests to the Visual Studio Team System unit testing framework. While I believe that the unit testing framework in VS 2005 has merits, I am not sure if I am ready to dump NUnit. NUnit has a major advantage over Visual Studio for the specific project I am working on: it can correctly compare the contents of arrays.

Suppose you have a custom class. In order to properly compare two instances, you override the Equals method. Both NUnit and Visual Studio Team System will use the Equals method in their respective Assert.AreEqual methods.

However, NUnit will compare arrays on an element-by-element basis, calling the Equals method on each element in the array. Visual Studio Team System expects you to iterate over the array and call Assert.AreEqual for each element (which I would think is what NUnit does under the covers (I haven’t actually looked at the source code, but it seems to make sense)). If you supply two arrays to Visual Studio’s Assert.AreEqual, then the unit test framework will consider the arrays equal if they refer to the same memory address (reference equality).

P.S.: There is one more difference that makes NUnit preferable in certain situations. NUnit introduces a concept of “Categories.” Each unit test can be assigned to one or more categories. You can then elect to only run unit tests in a specific category, or exclude unit tests from a specific category. For a large project, or a project where you know under certain circumstances tests will fail, this is particularly attractive.

UPDATE: According to the documentation, the Team Edition for Testers (and therefore Team Suite) provides the notion of Test Lists, which allow logical groups of tests to be created. Sadly, this means developers have to pay extra for this functionality if they choose to use the Team System testing framework.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s