Search Wiki:
The Microsoft Silverlight Unit Test Framework (Microsoft.Silverlight.Testing) is a simple, extensible unit testing solution for rich Silverlight 2 applications, controls and class libraries.

Unit Test Framework for Microsoft Silverlight 2


Silverlight 2
The source code to the unit test framework is now available on CodePlex: the Silverlight Toolkit
download new templates
breaking changes information

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. Windows and Mac. Safari, Mozilla Firefox, and Internet Explorer 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

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

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.

popular resources

Original tutorials, articles, and screencasts can be found at http://www.jeff.wilcox.name/blog/.

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. The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer in any way.
Last edited Dec 19 2008 at 6:22 PM  by jeffwilcox, version 42
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 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 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 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 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 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 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 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 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 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 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 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.

Updating...
Page view tracker