NUnit for Silverlight updated: NUnit 2.5.5, Silverlight 4

Some while ago, I’ve ported NUnit to Silverlight; that post has been a follow-up to to Jeff Wilcox’s description of how to write unit tests instead of the standard MSTest syntax.

Here’s an update for the ported version of NUnit for version 2.5.5, and for both Silverlight 3 and Silverlight 4.

To create a Silverlight unit test project that uses NUnit, follow these steps:

  • Download and extract the binaries, or download the source code and build the assemblies on your computer
  • Create a new Silverlight unit test project using the Silverlight unit testing framework (and of course if you don’t have it installed, you should do that by now).
  • Reference the three assemblies from the NUnit for Silverlight project.
  • In the App.xaml.cs file, register the NUnit unit test metadata provider. This is done in the StartUp event handler for the application, before the test page is created:
    private void Application_Startup( object sender, StartupEventArgs e )
    {
      UnitTestSystem.RegisterUnitTestProvider(
         new Microsoft.Silverlight.Testing.UnitTesting.Metadata.NUnit.NUnitProvider() );  
      RootVisual = UnitTestSystem.CreateTestPage();
    }
    

UPDATE

  • 11-May-2010: Fixed a problem with the Silverlight 4 port; an assembly from the Silverlight 3 testing framework had been referenced.
  • 11-June-2010: Updated the NUnit port, please see NUnit for Silverlight: Now with data driven tests
  • 01-Dec-2010: Moved the project to Google code, updated to NUnit version 2.5.8.

Download

Please download from nunit-silverlight on Google Code.

,

  1. #1 by Adrian on May 7, 2010 - 23:05

    Thanks for publishing this, it has really helped getting my project going with silverlight unit testing.

  2. #2 by Carel Lotz on May 31, 2010 - 11:59

    Thanks for publishing. Can you for future updates please sign the assemblies as well?

    • #3 by Christian on June 3, 2010 - 09:27

      Good point, will do.

  3. #4 by CarlzBad on August 5, 2010 - 00:53

    Is there a way to run these in nunit-console? I want to use this to run tests with ncover but am having some trouble figuring it out.

    • #5 by Christian on August 5, 2010 - 01:57

      Nope. The NUNit console does not support the Silverlight runtime. This project is only a port of the NUnit.Framework part that provides the test syntaxand assertions, nut the test runner. The tests still need to run under the MS Silverlight test runner. It is possible to collect covrage data, but you need Visual Studio 2010 Ultimate for that: http://www.jeff.wilcox.name/2009/11/november-walkthrough/

      • #6 by CarlzBad on August 5, 2010 - 02:40

        Thanks for the quick reply. I guess I am out of luck for now.

        Code coverage for Visual Studio 2010 got discontinued and stopped working in the RTM. I guess they were not kidding when they said it was experimental!

  4. #7 by Hugo Estrada on December 16, 2010 - 22:42

    Thanks so much for this port. It is going to help. I actually like the syntax of Nunit a lot, especially the newer constraint-based assertions; I believe that it makes the tests a lot more readable.

    Just one quick comment for other people who are trying to use this: after you follow your instructions, you set the testing project as the startup project, and then you hit f5.

  1. Tweets that mention NUnit for Silverlight updated: NUnit 2.5.5, Silverlight 4 « greenicicle -- Topsy.com
  2. Running NUnit 2.53 tests for Silverlight « greenicicle
  3. Yesterday’s Good and Bad in Silverlight « greenicicle
  4. Unit testing in Silverlight - YsA.Net
  5. asp.net, c#,javascript

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.