Here’s the next drop of my inofficial port of the NUnit unit test framework for Silverlight. It supports NUnit 2.5.5 on Silverlight 3 and 4, and I’ve added support for Jeff Wilcox’ port of the April version of the Silverlight testing framework on Silverlight 3.
And man, does that April version make a difference! Compare to the November 2009 release of the Silverlight unit testing framework, it’s not only nicer to look at – it runs a whole lot faster. If you’re already on Silverlight 4, you’re already using it anyway; but if you’ve still got a SIlverlight 3 project, I’d highly recommend you try the upgraded verion. Rewriting any of your test is not necessary, of course.
About this release
This release of the NUnit port consists of three Visual Studio projects for the different targeted platforms:
- Silverlight 3, with the unit testing framework from the November 2009 release of the Silverlight toolkit
- Silverlight 3, with Jeff Wilcox’s port of the unit test framework from the April 2010 of the Silverlight toolkit (which targets Silverlight 4 only)
- Silverlight 4, with the unit testing framework from the April 2010 of the Silverlight toolkit.
The actual NUnit code is shared between the projects, only the unit test framework specific code is different between the branches. In order to compile your own version, download the source code and find the version of your choice. If you have a version of the Silverlight toolkit installed that does not match the one you wish to compile, you might need to set the reference path inside the Visual Studio project for the MetaData and NUnit.Framework.Tests projects to the “lib” directory that contains the dependency assemblies.
The license of the project is a little bit of a mess: Yes, it’s all open source. But. NUnit has its own license, which also applies to the ported version, of course. The NUnit provider by Jeff Wilcox is however published under Ms-PL. I’ve got a strong feelign that these licenses are compatible and it could be possible to publish this port under just one license, but I’m no expert with this kind of problem, and need to get some advice first. In fact, this is the reason why I’m not putting the project up to Google Code or Codeplex – these platforms demand that you decide the license, and for the moment, I’d say there are two.
The version numbers have been changed to Year.Month.Counter; the current version is of all assemblies is “2010.6.1″. This version is neither strong-named nor signed; I’ll be changing that soonish, promised.
Data driven tests
One thing I wanted to include into the ported version of the NUnit framework were the tests included with the NUnit source code. In the source code for this version, you find one Silverlight application that implements these tests. Porting them, I found out about quite an important oversight: with NUnit 2.5, a powerful way of defining data driven tests was added; the ported version however did only support the [Test] attribute for standard tests.
The simplest way to define a data driven test for NUnit is to decorate a test with the [TestCase] attribute instead of (or, optionally, in addition to) the [Test] attribute. This attribute lets you define parameters and an expected result for a test. By decorating the same test with multiple [TestCase] attributes, you can cover a lot of test cases without having to write and maintain repetetive test code – you find the full documentation here. The SL3 and SL4 ports for the April 2010 version of the Silverlight toolkit now supports the [TestCase] attributes; the version for the November 2009 Silverlight toolkit does not.
NUnit also offers some attributes for more advanced data driven tests, these are not supported.
NUnit unit tests
I’ve ported the unit tests for the NUnit.Framework assembly to SIlverlight; however, not all tests did make it. The main reasons for a test being excluded are:
- The test refers to something in NUnit that could not be ported – like the assertions on serialization and directories.
- The syntax tests rely on compiling code as part of the test – Silverlight won’t let you do that; it clashes with the security restrictions (you don’t want an app runnign inside a browser to modify itself).
- The test is data driven and uses an attribute that is not supported in this version of the port – in fact, the April 2010 version included more tests because the [TestCase] attribute is supported there.
So: happy NUnit testing!
Please download from nunit-silverlight on Google Code.