Monday, 8 April 2013

How to use NUnit Assert functionality in MS Tests

Today I realised that I'd forgotten how spoilt I am using Resharper and dotCover to run my unit tests. Put another way I'd forgotten how badly Visual Studio plays with any other unit test frameworks other than MS Test! I'm used to and really like the fluent API style of NUnit's Assert.That(...) syntax so having to fall back to MS Test always feels like a step back. If you ever find yourself in a situation where you can only run MS Tests, but want to use NUnit functionality you can easily do this just by using aliases on the NUnit "using" statements.

The following "using" code block facilitates this - you will be able to decorate your unit test classes with MS Test attributes so they can be picked up and run by Visual Studio whilst using NUnit functionality.

using Microsoft.VisualStudio.TestTools.UnitTesting;
 
using Assert = NUnit.Framework.Assert;
using Is = NUnit.Framework.Is;