In the last post, I wrote about, how to use ReSharper with Silverlight Unit Test Projects. Now I can do TDD with Silverlight very easily.
But I don’t like the MSTest assertions syntax. In the Past I used NUnit to write my tests. How can I use the NUnit syntax inside the Silverlight unit tests?
My first Idea was to write the NUnit assertions syntax by my own to encapsulate the MSTest. But the easiest way is to really use NUnit assertions in MSTest
How does this work?
First of all:
Download NUnit for Silverlight: http://code.google.com/p/nunit-silverlight/ and reference to NUnit.Framework.
(Be sure the assemblies are unblocked. If not, unblock the assemblies in the file properties dialog)
Write a small alias in the usings of your test class:
using Assert = NUnit.Framework.Assert;
Now you can use the NUnit assertions syntax in your MSTest:
Assert.Throws<Exception>(() => hasItemsConverter.Convert(items, null, null, null));
This is not only a solution for Silverlight Unit Test, you can do this with all other MSTest where you want to use NUnit assertions
Why does that work?
Assertions are only simple tests. If the tests fail, a Exception will be thrown. This is the same procedure in all unit test frameworks. So you can mix the frameworks in your unit test projects.