Silverlight NUnit Projects

I've been doing some experiments to find out if it's possible to execute NUnit on a Silverlight project. I knew that Visual Studio 2008 and Expression Blend both host Silverlight for use in the designer window. It turns out that rather than host a separate instance of the CoreCLR, the designer simply loads the Silverlight assemblies into the host runtime. This simplifies the business of creating a compatible unit testing framework considerably!

With a little bit twiddling, I've managed to tweak the 'nunit.framework' assembly so that it's compatible with Silverlight projects. In order for your tests to execute successfully, you also need to ensure that all Silverlight assemblies (except 'mscorlib') are set to 'Copy Local: True'. After this is done you can run, debug and even do code coverage on your Silverlight unit tests!

Because creating one of these projects is a fiddle to set up, I've created Silverlight NUnit Project template that does the work for you. To install the template simply open the 'SilverlightNUnitProject.vsi' file and ignore the unsigned content warning. Once installed, you will find it under the 'Visual C# / Silverlight' section of the 'New Project' dialog. You can download the template from here.

SilverlightNUnitProject 

To execute one or more unit tests you should use 'Run Test(s)' rather than 'Test With > Silverlight'.

RunTests

In summary you now have 3 options when testing Silverlight projects.

  1. For unit testing you can create a Silverlight NUnit Project and use the usual TestDriven.Net commands.
  2. For integration testing (within the context of a browser) you can use the Silverlight Testing Framework.
  3. For spelunking individual methods inside the CoreCLR you can use 'Test With > Silverlight'.

I'd be interested to hear how you get on.

Published Thursday, May 01, 2008 3:34 PM by Jamie Cansdale

Comments

# Silverlight NUnit Projects - TestDriven.NET by Jamie Cansdale

Pingback from  Silverlight NUnit Projects - TestDriven.NET by Jamie Cansdale

# Silverlight TDD with NUnit « SilverRogue

Pingback from  Silverlight TDD with NUnit « SilverRogue

Friday, May 02, 2008 4:46 AM by Silverlight TDD with NUnit « SilverRogue

# re: Silverlight NUnit Projects

Thanks Jamie. Just tested it out on some unit tests I'm currently porting to Silverlight. Works a treat!

Friday, May 02, 2008 4:49 AM by Mike Saunders

# re: Silverlight NUnit Projects

YOU ROCK MAN!!!!!!!!!

Friday, May 02, 2008 9:01 AM by Marlon Grech

# Developer News » Blog Archive » Spam reaches 30-year anniversary The first junk e-mail or spam

Pingback from  Developer News  » Blog Archive   »  Spam reaches 30-year anniversary The first junk e-mail or spam

# Silverlight NUnit Projects | Silverlight Guide

Pingback from  Silverlight NUnit Projects | Silverlight Guide

Sunday, May 04, 2008 8:17 AM by Silverlight NUnit Projects | Silverlight Guide

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# SilverlightShow.net

I've been doing some experiments to find out if

Sunday, May 04, 2008 4:51 PM by SilverlightShow.net

# Developer News » Blog Archive » CodeSnip: How to Select the Records from a Table Following

Pingback from  Developer News  » Blog Archive   »  CodeSnip: How to Select the Records from a Table Following

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Kraken bot cracked open to reveal source code Security vendor

Pingback from  Developer News  » Blog Archive   »  Kraken bot cracked open to reveal source code  Security vendor

# Developer News » Blog Archive » Utilizing your .NET Projects Automated Acceptance Tests on Crystal Reports

Pingback from  Developer News  » Blog Archive   »  Utilizing your .NET Projects Automated Acceptance Tests on Crystal Reports

# re: Silverlight NUnit Projects

You a a true developer - nice work! PK :-)

Sunday, June 01, 2008 5:29 PM by Paul Kohler

# Developer News » Blog Archive » compare cell values how to compare cell values in editable

Pingback from  Developer News  » Blog Archive   »  compare cell values    how to compare cell values in editable

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# What Is Coming In Json.NET 2.1

I have just checked in two new features coming soon in Json.NET 2.1: Silverlight client support and improvements

Sunday, June 08, 2008 6:44 AM by James Newton-King

# Developer News » Blog Archive » TestDriven.Net 2.11: Parameterized NUnit TestsTestDriven.Net has always supported parameterized test

Pingback from  Developer News  » Blog Archive   »  TestDriven.Net 2.11: Parameterized NUnit TestsTestDriven.Net has always supported parameterized test

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Facebook website outage resolved An outage which knocked popular social

Pingback from  Developer News  » Blog Archive   »  Facebook website outage resolved An outage which knocked popular social

# re: Silverlight NUnit Projects

This is a great piece of work. I've encountered a few issues when using it with non-mscorlib assemblies (like System.ServiceModel.Web); Everything compiles but I encounter either a MissingMethodException or a "failed to load" exception. The latter is cured by pulling in all of the SDK reference assemblies into the \lib\ directory and basing all project references from there. The latter, which occurs on methods like AutoResetEvent.WaitOne(), I can't find a solution for. I don't know where or how the unit test project is pointing to the wrong assembly, or an unloaded one considering WaitOne() is present in both .NET and Silverlight System.Threading namespaces (mscorlib.dll). Besides these issues this is a great alternative for the time being.

Monday, June 30, 2008 10:55 AM by Daniel

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# re: Silverlight NUnit Projects

Is this 'little bit' of 'tweaking' possible for nmock too?!

Thank You,

Jasonlan

Tuesday, July 08, 2008 2:11 AM by Jason Schluter

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » The Morning Brew #143 Another slow day in .NET land

Pingback from  Developer News  » Blog Archive   »  The Morning Brew #143 Another slow day in .NET land

# Thinking about Silverlight and Mocking » Mark Monster

Pingback from  Thinking about Silverlight and Mocking » Mark Monster

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Seeking advice with Dreamweaver… Hi there, I just joined this

Pingback from  Developer News  » Blog Archive   »  Seeking advice with Dreamweaver…    Hi there, I just joined this

# Developer News » Blog Archive » Digital nomad drives laptop sales The world’s second largest PC

Pingback from  Developer News  » Blog Archive   »  Digital nomad drives laptop sales The world’s second largest PC

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Mocking and IOC in Silverlight 2, Castle Project and Moq ports

Mocking and IOC in Silverlight 2, Castle Project and Moq ports

Friday, August 15, 2008 5:19 AM by Flawless Code

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

# Developer News » Blog Archive » Links for 2008-08-29 [del.icio.us] Open Source PHP Site containing loads

Pingback from  Developer News  » Blog Archive   »  Links for 2008-08-29 [del.icio.us] Open Source PHP Site containing loads

# Developer News » Blog Archive » ‘Preflight’ Your Builds for More Continuous Integration If you’re part

Pingback from  Developer News  » Blog Archive   »  ‘Preflight’ Your Builds for More Continuous Integration  If you’re part

# Developer News » Blog Archive » Overview of Microsoft Office SharePoint Server 2007 In this article,

Pingback from  Developer News  » Blog Archive   »  Overview of Microsoft Office SharePoint Server 2007     In this article,

# Developer News » Blog Archive » can i mearge C# and vb code in one project

Pingback from  Developer News  » Blog Archive   »  can i mearge C# and vb code in one project

# Friday Links #19 | Blue Onion Software *

Pingback from  Friday Links #19 | Blue Onion Software *

Friday, October 03, 2008 1:55 PM by Friday Links #19 | Blue Onion Software *

# re: Silverlight NUnit Projects

Thanks for doing this!

Could you please elaborate on what "tweaking" you had to do? I am interested in adding running these tests via msbuild/nant and from ReSharper. Any suggestions?

Thursday, October 23, 2008 1:35 PM by Declan Whelan

# Nunit和TestDriven测试

1.TestDriven测试工具下载路径:http://www.testdriven.net/

2.TestDriven测试工具安装的时候已经包括了,Nunit的测试工具,只要在其安装文件下边找到n...

Tuesday, November 25, 2008 4:06 AM by sunlibo

# Developer News » Blog Archive » Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Pingback from  Developer News  » Blog Archive   »  Silverlight NUnit ProjectsI’ve been doing some experiments to find out

Leave a Comment

(required) 
(required) 
(optional)
(required)