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

# 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

Tests involving isolated storage cannot be executed using this framework. Try this

[Test]

public void Iso()

{

   using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())

   {

       using (IsolatedStorageFileStream stream = iso.OpenFile("test.txt", FileMode.Create))

       {

           stream.Write(new byte[] { 4, 6, 2 }, 0, 3);

       }

   }

}

and you get

TestCase 'SilverlightNUnitProject2.SilverlightTests.Iso'

failed: System.MissingMethodException : Method not found: 'System.IO.IsolatedStorage.IsolatedStorageFileStream System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(System.String, System.IO.FileMode)'.

at SilverlightNUnitProject2.SilverlightTests.Iso()

I'll stick with the browser integrated tests :(

Thursday, July 30, 2009 10:22 AM by Martin Ørding-Thomsen

# re: Silverlight NUnit Projects

I updated the assemblies to version 2.5.1 of the NUnit framework, here's my blog post explaining what I did and the links to download it:

wesmcclure.tumblr.com/.../152727000

Friday, July 31, 2009 12:57 AM by Wes

# re: Silverlight NUnit Projects

Any plans to post the ported NUnit code?

Saturday, August 01, 2009 4:12 PM by Scott Marlowe

# re: Silverlight NUnit Projects

Good work. The hints will be helpful in adding this to NUnit. Is there some reason you didn't want to contribute the code?

Thursday, September 17, 2009 1:30 AM by Charlie Poole

# re: Silverlight NUnit Projects

@Charlie No reason. It was very experimental at the time. It uses some ilasm / ildasm tricks and I never got around to automating it. I'd be happy to contribute. :)

Friday, September 18, 2009 7:38 AM by Jamie Cansdale

# re: Silverlight NUnit Projects

Great work Jamie. It is now easy to get our Silverlight unittests running in TeamCity, great! All we have to do is specify the exact NUnit version of the modified NUnit-assembly in our MSBuild-script, and TeamCity picks it up.

<NUnitTeamCity Assemblies="@(TestAssemblies)" NUnitVersion="NUnit-2.4.7" />  

I am using TeamCity 4.5.5.

Friday, September 25, 2009 5:33 AM by Andreas Hallberg

# re: Silverlight NUnit Projects

Nice work.  Anybody been able to test against a web service yet?  I'm close.  Had some problems w/ System.ServiceModel and System.Runtime.Serialization, but you mentioned setting "Copy Local=true", and that got me passed that.  Now it's complaining "ConfigFileMissing", and I can't seem to convince it to use the one I have in the project.

Monday, March 22, 2010 5:05 PM by Eric

# re: Silverlight NUnit Projects

Does it work with methods that utilize from a WCF RIA Service?

In my experiences, there were several libraries that I had to include to the test project: System.ServiceModel, System.Net, System.Windows.RIA. But the NUnit.exe still complains about a missing library: agcore.dll. It is in the ReferenceAssemblies folder but somehow NUnit.exe cannot see it. I manually copied the agcore.dll to the ClientBin folder. Now, it gives "Catastrophic failure" error. I am stuck at this point.

Wednesday, March 31, 2010 5:29 AM by Can Kayacan

# re: Silverlight NUnit Projects

Yes I agree with the above posters. With silverlight in such an advanced state I must say it is sad to see the tooling for robust unit tests still lagging behind.

Not to say this project isnt EXTREMELY helpful, but when you get errors related to System.Net dll missing, you are stuck.

Tuesday, April 13, 2010 3:33 PM by pete w

# re: Silverlight NUnit Projects

I've run into a strange problem when trying to create a WebRequest used in an asynchronous call within a unit test.  I consistently get a NotSupportedException: net_unknown_prefix error when I pass my Uri into the followiing line of code:

   var request = (HttpWebRequest) WebRequest.Create(uri);

The uri in question is pretty straightforward; localhost/.../Lists.asmx

The prefix is simply http, hence I'm kind of puzzled by this error.  Any ideas what is going on here?      

Sunday, May 23, 2010 9:53 PM by Rob Lebowitz

# re: Silverlight NUnit Projects

@Rob Could you try running this test using the Silverlight Unit Test Framework:

www.jeff.wilcox.name/.../new-2010-test-framework

Monday, May 24, 2010 4:44 AM by Jamie Cansdale

# re: Silverlight NUnit Projects

FYI - I was able to use your templates to test my Windows Phone 7 app after some tweaks.  Check out the blog post where I explain.  Thanks for the great Silverlight templates!

dotnetcatch.wordpress.com/.../unit-testing-nunit-a-wp7-project

Monday, July 26, 2010 12:25 AM by Robb Schiefer

# re: Silverlight NUnit Projects

Blogroll links aint that great :P but i'm not the admin… :P … Just Telling :P

--------------------------------------------

my website is  

http://ogre-store.com

Also welcome you!

Wednesday, November 24, 2010 8:07 AM by P bass

# re: Silverlight NUnit Projects

The best hearts are always the bravest.

-----------------------------------

Saturday, December 18, 2010 11:53 AM by ipad app tracker

# re: Silverlight NUnit Projects

Great read! I want to see a follow up to this topic :D

<a href="www.live-boys-webcam-chat.com/.../a>

Wednesday, December 29, 2010 6:34 AM by Eliseo

# re: Silverlight NUnit Projects

-----------------------------------------------------------

"Looks to me like Obama took out the troops to soon if we can not get any NATO troops ? Does Obama ever talk about this ? Just what is heading on in  Afghanistan. Appears our troops are sitting ducks these days. Seems Iraq and also the 30,000 American troops are heading to find out a entire good deal a lot far more  fighting inside the subsequent couple of months. Will Obama even look to find out what's occurring?"

Sunday, January 09, 2011 9:04 AM by ipad reviews

# re: Silverlight NUnit Projects

I am happy you took the time and wrote that post!

<a href="www.oregonlngpropertysearch.com/">moncler jacket</a>

Tuesday, January 25, 2011 12:36 PM by Kenton Garrett

# re: Silverlight NUnit Projects

Bill, WTF...

Yours

Monica

<a href="www.nacht-creme.net/">vichy nachtcreme"</a>

Wednesday, January 26, 2011 1:05 PM by Diana Riddle

# re: Silverlight NUnit Projects

Denny, whatever dude..

<a href="www.oregonlngpropertysearch.com/">moncler jacket</a>

Monday, February 07, 2011 1:07 AM by Kristi

# re: Silverlight NUnit Projects

I'm having troubles getting this working against a SL4 project with WCF RIA. I've updated the NUnit test projects SL version to 4 and added the WCF RIA link to my project. Then I made sure that all of the references were CopyLocal=True (except for mscorlib). Now, however, when I run tests, I get

System.TypeInitializationException : The type initializer for 'MS.Internal.JoltHelper' threw an exception. --

Should I not be trying this with WCF RIA?

Monday, February 07, 2011 11:31 AM by David

# re: Silverlight NUnit Projects

Silverlight nunit projects.. Awesome :)

Sunday, March 27, 2011 2:36 PM by weblogs.asp.net

# re: Silverlight NUnit Projects

Coachella--and, for all intents and purposes, the entire summer concert season--kicked improbable Friday in California's Indio arid, and the three-day mega mellifluous birthday was a sold-out amour ignoring the in touch set-back and unending whiny complaints just about this year's "stupid" lineup. (Um, hello: Kanye West, Duran Duran, the Strokes, the comeback of Britpoppers Suede, late Album of the Year Grammy champs Arcade Intensity, and uncountable more? How is that "indiscernible"?) Surely, the anniversary offered<a href=nasze-wczasy.pl/>biuro podr&#243;&#380;y</a> the entirety any self-respecting nut of music (or neutral gaiety) could have a yen for:

Monday, April 18, 2011 6:42 PM by biuro podr&#243;&#380;y

# re: Silverlight NUnit Projects

Coachella--and, after all intents and purposes, the entire summer concert season--kicked off Friday in California's Indio jilt, and the three-day mega melodic birthday was a sold-out activity teeth of the in touch recession and perpetual whiny complaints around this year's "weak" lineup. (Um, hello: Kanye West, Duran Duran, the Strokes, the comeback of Britpoppers Suede, just out Album of the Year Grammy champs Arcade Fire, and uncountable more? How is that "weak"?) Undeniably, the anniversary offered <a href=xanonseerotyczne.pl/>anonse erotyczne</a>

the entirety any self-respecting nut of music (or justifiable game of) could crave:

Friday, April 22, 2011 10:30 AM by anonse erotyczne

# re: Silverlight NUnit Projects

Had anyone got this working after upgrading to Wp 7.1 (Mango)?

After upgrading my project the unit test assemblies are not loaded and VS gives the following error message:

"An attempt has been made to add an unsupported reference. You can add project references only to other Windows Phone with same or lower version, XNA for Windows Phone or Silverlight projects in the solution."

After checking the .proj properties were correct I decided to re-create the unit test assembly. It now loads, but I get an InvalidProgramException when trying to run the tests.

Would love to get it working as its a great solution for unit testing! Thanks Jamie :)

Tuesday, June 07, 2011 6:23 AM by m

# re: Silverlight NUnit Projects

I don't know if it's just me or if everyone else encountering difficulties together with your site. It appears as if a number of the written text on your content are running off the screen. Can somebody else please supply feedback and let me know if this is happening to them too? This could be a challenge with my internet browser for the reason that I've had this occur prior to.

Friday, July 01, 2011 10:00 AM by Nana Poyser

# re: Silverlight NUnit Projects

Hey there! Fast question that's totally off subject. Do you know how to make your web site mobile friendly? My internet site looks weird when viewing from my iphone. I'm attempting to obtain a template or plugin that may possibly be able to fix this issue. For those who have any suggestions, please share. With thanks!

Tuesday, July 05, 2011 9:35 AM by Jon Sbarra

# re: Silverlight NUnit Projects

I really liked the article, and the very cool blog

Monday, August 22, 2011 11:42 PM by rtyecript

# re: Silverlight NUnit Projects

el Absurdo por que esto      

http://www.shampes.com/      

fletcher

Monday, September 05, 2011 8:23 PM by sydne

# re: Silverlight NUnit Projects

halla www.pozycjonowaniezak47.pl  allowable idea because of be germane to from you as repeatedly

Tuesday, January 31, 2012 6:48 PM by pozycjonowanie

# re: Silverlight NUnit Projects

hi www.thejavacode.com/memberlist.php  textile concept due to the fact that partnership from you as repeatedly

Thursday, February 02, 2012 1:35 AM by pozycjonowanie warszawa

Leave a Comment

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