NUnit for Silverlight, now with data driven tests


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.
  • Download

    So: happy NUnit testing!
    Please download from nunit-silverlight on Google Code.

    About these ads
    About

    Christian is a software architect/developer. He lives in Germany, reads a lot, and likes cycling.

Tagged with: ,
Posted in Coding, Testing
7 comments on “NUnit for Silverlight, now with data driven tests
  1. Tobias says:

    Data driven tests, huh, that’s pretty cool! Does this go on and we get keyword driven tests next?

  2. [...] Updated the NUnit port, please see NUnit for Silverlight: Now with data driven tests Possibly related posts: (automatically generated)Running NUnit 2.53 tests for SilverlightFree [...]

  3. Mark says:

    Wow, if only you had posted this earlier it would have saved me a whole lot of trouble. Anyway, thanks for updating the nunit for 2.5.5. Much appreciated!

  4. Carel Lotz says:

    Any news on updating this to work off the latest NUnit 2.5.7 release?

    Thx

    • Christian says:

      Plans: yes. Started:no. I’m currently between jobs, and keeping the blog and NUnit updated is not my primary concern at the moment… In some weeks, I’ll be back to normal. I also want to get the license cleared up, and move the project to a robust hosting platform. So bear with me a little, an update is going to come.

  5. Sun Venu says:

    Are you planning on updating this to support Silverlight 5 too?

    • Christian says:

      Honestly: I had this on my plate for some time now, but it turns out I just don’t do any Silverlight related work any more, and I haven’t even installed SL5 so far. So going forward with this port is both less rewarding (because I don’t use it myself any more) and harder. So this answer is no, I won’t, I just came to accepting that.

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: