Search Wiki:
Microsoft Silverlight Unit Test Framework
The Microsoft Silverlight Unit Test Framework is a simple, extensible unit testing solution for Silverlight developers.

unit testing for silverlight
This test framework is a solution built by developers, for developers, to help get a jump start on building richer applications and components for Microsoft Silverlight 2. The framework is currently available as a binary download for use in your own applications. We first released this framework along with the source code and unit tests to the Silverlight controls at the MIX '08 conference in Las Vegas earlier this year.

The unit test framework is compatible with Microsoft Silverlight 2 Beta 1 and Beta 2. It supports Mac and Windows testing, on all Silverlight browsers, including: Safari, Firefox, and Windows Internet Explorer.

More information about the Silverlight Unit Test Framework, including tutorials and articles, can be found at http://www.jeff.wilcox.name/blog/.

coming soon
A refresh to the test framework's bits for Beta 2 (more):
  • updated, easy-to-discover APIs
  • user interface improvements, including a progress bar and basic run statistics
  • simplified extensibility points and logging concept
  • command line and continuous integration support

simple. powerful. extensible.
  • unit tests run right inside the web browser
  • enables testing of rich controls and the entire Silverlight platform
  • rich in-browser logging
  • basic asynchronous testing support

same framework as visual studio
The Microsoft unit test framework is one of several popular .NET unit testing metadata choices out there (learn more). Around since Visual Studio 2005, we decided to make it easier for everyone to get started in the Silverlight world by using the same metadata. The Silverlight unit test framework includes the same assertions and metadata that you'll find in Visual Studio 2008 Professional.

If you're new to Microsoft's effective and easy-to-use unit test framework, then you'll be able to use your Silverlight testing knowledge while building applications on the full .NET framework platform, including Windows Forms, WPF, and .NET 2.0 through 3.5 class libraries.

sample application screenshot
Sample rich test application running inside of the Apple Safari browser on Mac OS X 10.5

title_popular_resources.png

release information
What happens in Vegas sometimes leaves Vegas. The current release came out alongside Silverlight 2 Beta 1, announced in Scott Guthrie's keynote at MIX '08. The unit test framework was used to help build the controls inside Silverlight. This is all part of the "new Microsoft" for developers: product source code. unit tests. a unit test framework.

Hope you like where this is all headed,

Cannot resolve link: [image:jeff|unofficial_s.png]
Jeff Wilcox
Software Development Engineer
Microsoft Corporation
http://www.jeff.wilcox.name/
contact

Microsoft.Silverlight.Testing is not an officially supported Microsoft product. This is not a CTP, nor a Beta: we're simply sharing our in-browser testing platform hoping that you'll find that it's useful and rocks.
Last edited Sep 16 2008 at 6:56 AM  by jeffwilcox, version 25
Comments
cobyjone wrote  Sep 24 2008 at 3:37 PM  
I love using this to unit test our silverlight apps. Is there any chance that either a similar library will be released for WPF or the source code will be released? I think that the way that this library handles async UI unit testing would also be useful for WPF desktop applications as well.

jeffwilcox wrote  Sep 25 2008 at 9:27 AM  
@cobyjone, we're definitely looking into what it would take to release this project on CodePlex. Do stay tuned, I think it would be a great thing to see. - Jeff

wpqs wrote  Oct 17 2008 at 12:52 AM  
the RTW download doesn't seem to contain the Microsoft.Silverlight.Testing.Framework. If you have installed the prebuilt templates (option 2, in http://www.jeff.wilcox.name/2008/03/31/silverlight2-unit-testing/ ) then you need to remove the call to InitializeComponent() in App.xaml.cs and also remove the parameter from UnitTestSystem.CreateTestPage() in the Application_Startup method. That done, you should be able to get to your first failing test. Will Stott

jeffwilcox wrote  Oct 18 2008 at 10:14 AM  
Thanks Will. We merged the 2 framework assemblies into a single one this time around, but haven't released the updated templates. I'll try and get those added, sorry!

Toddpi314 wrote  Oct 23 2008 at 9:47 PM  
Unit Testing is vital. The Silverlight Test Project is very helpful, but...

Will we see this integrated into VS.NET Unit Test IDE Tools? By this, I mean, can this project be updated in order to use in the Test View/Results items in VS.NET 2008, as well as support TFS Client Integration.

This is a key requirement, as across our Enterprise we all balance on MSF Workflow using the Foundation Server Tools (via TSF Build Exporer Client)
It has become increasingly difficult to maintain work items, associate test run stats and binaries to newly created items, etc.

Tell me what I can do to help, if this is not a feature that will be supported soon.

cmichaelgraham wrote  Jan 5 2009 at 3:32 PM  
I enjoy your postings. Here is a use case that I feel is probably very common:

I am interested in a simple process for "unit testing" my WCF web services from Silverlight to make sure I have created the proper configuration. I am using a dual-targeting approach as outlined in CompositeWPF project on CodePlex.

I have done some digging and haven't found a simple answer, so I am resorting to a simple Silverlight application and companion web application to perform the tests.

It would also be very nice if I could just link in the test classes from the WPF unit testing project.

Pieterv wrote  Jan 20 2009 at 1:23 PM  
Jeff,

It's a great framework thank you very much but, I'm missing the Microsoft.Silverlight.Testing.Framework.dll in the release version. Don't we have to use this dll anymore? Also the project and class templates are not availble for release?
Do you have an indication when these templates are available?

Tanks,
Pieter

dps wrote  Feb 24 2009 at 6:04 PM  
Hey, thanks for this. I do have a problem though. Whenever I run the tests and anything fails the application throws an exception and breaks--obviously not desirable. How do I get around this?

Thanks,
Dan

theotherjay wrote  Mar 17 2009 at 6:21 PM  
I am having the same issue. If any of my assertions fail, the application breaks at the assertion error (e.g., If Assert.IsNotNull(...) is false then the application breaks). How can I get the test framework to complete all the tests without breaking at an assertion failure?

theotherjay wrote  Mar 17 2009 at 7:05 PM  
I have setup this test class to not break at each exception, however it still breaks. Here is my code:

[TestClass]
public class MainWindowTest: CustomFrameworkUnitTest
{

[TestInitialize]
public void setInterceptUnhandledExceptionsTrue()
{

InterceptUnhandledExceptions = true;
}

[TestMethod]
public void failure1()
{
try
{

Assert.IsFalse(true, "Should be false");
}
catch (Exception ex)
{
this.HandleException(ex);
}
}
[TestMethod]
public void falure2()
{
Assert.IsTrue(false, "should be true");
}

Neither of these work arounds have worked.

jbloomer wrote  Apr 8 2009 at 8:39 AM  
Has anyone got this framework working with the Silverlight 3 Beta? It doesn't seem to be able to resolve styles in the application resources.

aghoda wrote  May 2 2009 at 7:38 PM  
Is it a known issue: Application is breaking when any assertion fails? Your immediated comment is appreciated. I tried with SL 2 and SL 3, I am getting the same results.

Konamiman wrote  May 15 2009 at 7:19 AM  
It is not working for me. When I run the test project, the browser just displays a message saying that the TestPage.html page is not found. Isn't this page supposed to be created dinamically?

Konamiman wrote  May 15 2009 at 8:23 AM  
Additional information: when I try to build (not run) the solution (which contains just the Silverlight test project and a Silverlight class library), I get this compilation error: "Unexpected error in task 'ValidateXaml': parameter 'message' can't be null".

sorenenemaerke wrote  May 15 2009 at 3:47 PM  
Would like to run our Silverlight unit tests as part of a nightly build. Do I need to somehow host the build SL unittest project in Casini/IIS, hit the browser and screen-scrape or are there a nicer way? Does anybody have experiences with this?

aghoda wrote  Jun 15 2009 at 12:37 AM  
If you run the project in without debugging mode (ctrl + f5) or right click on the test web page and select option "View Browser", shoud work.

jeffwilcox wrote  Jul 14 2009 at 1:16 AM  
@sorenenemaerke, I'm working to get the test automation solution released that we use with this framework for our nightly builds on the Silverlight Toolkit. Unfortunately these things take time.

AdamPo wrote  Jul 28 2009 at 10:55 PM  
@jeffwilcox @sorenenemaerke, Integrating with Visual Studio and TFS and being able to automate running Silverlight tests would be a big win for our team too.

bill_cohagan wrote  Aug 8 2009 at 11:11 PM  
I've just downloaded/installed the various components for the framework for Silverlight 3. Writing my first test cost me about an hour because the ItemTemplate does *not* derive the test class from SilverlightTest! I searched high and low to find out why the heck EnqueueTestComplete() was undefined. The ItemTemplate also lacks a using for Microsoft.Silverlight.Testing namespace.

So, is there a forum somewhere so that users of this software might collaborate and share their successes and failures?

In any case, thanks for making this available. I assure you, my solution for unit testing async methods was a *lot* less elegant than yours!

Neville wrote  Aug 12 2009 at 8:02 AM  
The project template hasn't been updated to reflect the new assembly versions.

samir_ad wrote  Aug 28 2009 at 5:55 PM  
Can somebody guide me how to debug a single test case. I have 100 test cases and in order to debug one, i need all of them to execute. Is there any way out where i can only debug a single test case?

AdamPo wrote  Aug 29 2009 at 2:13 AM  
Is there a way (hopefully a fairly simple way) to impersonate a different user for a unit test? Either for a specific TestMethod or impersonate a user for all the TestMethods in a TestClass.

The Microsoft.VisualStudio.TestTools.UnitTesting.Web namespace has the CredentialAttribute, but that's not available in Microsoft.Silverlight.Testing.

DeputyVanHalen wrote  Sep 10 2009 at 2:25 PM  
Not to put a damper on the hard work that I'm sure went into this.... but until automation is available, it is akin to eye candy... useless in real life. I'm looking forward to when this is added, but until then must look elsewhere.

SanDimasHighSchoolFootballRules

Gamegineer wrote  Sep 30 2009 at 6:28 AM  
This doesn't compile for Silverlight v3.
Error 1 The name 'InitializeComponent' does not exist in the current context ...\SilverlightUnitTests\App.xaml.cs
Error 3 Argument '1': cannot convert from 'SilverlightUnitTests.App' to 'Microsoft.Silverlight.Testing.UnitTestSettings' ...\SilverlightUnitTests\App.xaml.cs


Here's the file created from the blog description:

using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Silverlight.Testing;
using System.Net;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace SilverlightUnitTests
{
public partial class App : Application
{

public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;

InitializeComponent();
}

private void Application_Startup(object sender, StartupEventArgs e)
{
// Load the main control
this.RootVisual = UnitTestSystem.CreateTestPage(this);
}

private void Application_Exit(object sender, EventArgs e)
{

}
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{

}
}
}

bbakermai wrote  Oct 13 2009 at 3:28 PM  
@jeffwilcox I love this framework! I have AutomationUI working against a WCF service using a delay timer, Async methods, and a ButtonAutomationPeer, but have also implemented a Silverlight Init Paramater (retrieved in App.xaml.cs) to self-locate the back-end Web Service in the real application. Has there been any thought to opening up the TestPage.html creation, giving the test author access to the Silverlight Object tag (before/during creation of the TestPage.html) in order to inject an Init Parameter using the Page.Request object to get the url of the service? If I missed something in the docs, please illuminate! Thanks again.

ASeale wrote  Oct 20 2009 at 5:32 PM  
Just wanted to throw out the comment that I love this framework. One question though, and this has nothing to do with the actual framework, but I was looking at the screenshot on this page and I noticed the caption: "Sample rich test application running inside of the Apple Safari browser on Mac OS X 10.5" Isn't that actually Firefox not Safari? :)

dbaechtel wrote  Nov 5 2009 at 12:26 AM  
The link to the Breaking Changes Information on this page is Broken. Please fix. Thanks.

samir_ad wrote  Dec 1 2009 at 10:24 PM  
I have 200 test cases written in Silver light test framework. I could not find a way to run or debug test cases individusally? Is there any way that i can run/debug a single test case at once??Please help this is bothering me since long time.

fresh_ant wrote  Apr 5 2010 at 5:03 PM  
Will this framework support asynchronous testing from silverlight? If not can you recommend some framework that supports this...

slawekaleksiuk wrote  Jun 14 2010 at 7:48 AM  
On the result page of test method, there are informations such as:

Test informations
Result:
Assembly:
Namespace:
[...]
Executing timing
Started:
Finished:
Elapsed time:
Output:

Do I have access to this last section "Output"? Can I add message to it from my test methods? If yes, please tell how. Thanks.

Kpatton wrote  Jul 17 2010 at 1:07 PM  
http://www.markerstudio.com/technical/2010/07/mvvm-light-and-unit-testing-example/

I've written an article based on latest beta for using sl unit test in framework and mvvm light with sample code

guzman wrote  Sep 1 2010 at 10:32 AM  
Hello.
I have a problem. I installed the Toolkit but I have no Silverlight Test Project in My Templates.
Why is this happening?

Thanks.

cdmoye wrote  Oct 14 2010 at 7:45 PM  
@jeffwilcox, any update on providing a mechanism to run Silverlight Unit Test Framework projects via msbuild?

jcouchara wrote  Feb 22 2011 at 6:06 PM  
Hello, I was wondering when silverlight unit testing will be integrated with TFS so that we can execute the tests via Test View in Visual Studio 2010? What is the current plan to support this? Without this, it is difficult to map our unit tests to associated product backlog items in TFS. Thanks.

waihibeachian wrote  Mar 12 2011 at 12:04 AM  
Hi Jeff Firstly, I love the unit testing framework what a difference this has made to our product. I have a small new feature request for you. Where the classes are shown on the left after they have been unit tested could you postfix the number of tests in that particular class in brackets?

Thanks

Serializable wrote  Jul 14 2011 at 3:41 PM  
Hi Jeff.
A couple quick questions:
1) would you expect a test to fail if a TestInitialize method throws an exception?
2) is there any way to use asynchronous (EnqueueXXX) methods in TestInitialize and TestCleanup?
On another note, is there any forum somewhere where people could discuss SUTF issues?

Thanks,
Dan

prachikh wrote  Jun 22 2012 at 11:41 AM  
Hi Jeff,

I could not find a way to run or debug test cases individually in silverlight unit test framwork.
can you please guide on the same and Could you please provide example from scratch to automate Silverlight 4 application.

Thanks..

Updating...
Page view tracker