NUnit Parameterized Testing and Visual Studio Integration

Over ten years ago, I started testing my code with NUnit.  At the time it did not have two of the features I will review today, parameterized testing and Visual Studio integration.  Because of this I had switched to MSTest for most of my recent projects.  I am now going to use NUnit in my new projects.

Jermey Clark recommended that I take another look at NUnit.  He is my mentor and frequent guest at the Central California .NET User Group.  

 

NUnit Packages

At the time of this writing, there are some unfortunate version issues you must be aware of.  Visual Studio integration will only work with NUnit version 2.4.6.  The latest version is currently 3.0.1.  This is because of another package called, NUnitTestAdapter.  That package gives Visual Studio the ability to populate the Test Explorer tab showing the test results.

Versions

 

Visual Studio Integration

With the NUnitTestAdapter installed the test methods will now show in the Test Explorer tab in Visual Studio.

Test Explorer

 

Parameterized Unit Tests

Below is some sample code showing a regular Unit Test compared with a parameterized Unit Test.  With this feature you can test multiple parameters in one test using attributes on the method parameters.  If you had more then one parameter you would add an attribute for each one.

Test Code

 

If you found this article helpful, use the tweet button below to spread the word.  Thank you.

 

Leave your comment
Comments
3/4/2016 1:58 PM
NUnit 3 is supported in Visual Studio, it just uses a different adapter, the NUnit 3 Test Adapter, https://visualstudiogallery.msdn.microsoft.com/0da0f6bd-9bb6-4ae3-87a8-537788622f2d. You can install both adapters side-by-side if you are working on NUnit 2 and 3 projects. We did this because NUnit 3 is a ground up rewrite and needs a different runner.
3/4/2016 3:50 PM
Thank you for the clarification.  This is great news!