One of the important capabilities we shipped with the Beta1 release of Silverlight 2 was a unit test harness that enables you to perform both API-level and UI-level unit testing. This testing harness is cross browser and cross platform, and can be used to quickly run and verify automated unit tests:
In addition to shipping this unit test harness for Silverlight, we also shipped the source to ~2,000 unit tests built with it that provide automated coverage for the Silverlight control source that we also shipped under a permissive license (you can take the control source, modify it, run the unit tests to verify the behavior, then re-ship the controls however you want).
Learning How to Unit Test Silverlight
Jeff Wilcox (who developed the Silverlight unit test framework and harness) has a great blog post that talks about how to add a Silverlight Unit Test project to a solution here. You can download the chat application that he shows testing from this expression blend blog post tutorial I did last month. You can also watch this cool video post that Jeff created where he walks through the unit test framework and test cases we’ve shipped.
As Jeff shows in his post, you can now add a "Silverlight Test Project" to your Visual Studio solution which encapsulates unit tests for an application you are working on:
You can then add unit test classes to the test project that test APIs or simulate UI action within the Silverlight controls (simulate button clicks, etc).
You can then run the test project and execute the tests within it to verify and report their status.
Jeff’s test framework automatically provides a browser based test harness and reporting system (which means you can run it on any browser/OS combination that Silverlight runs on):
Jeff’s test framework supports quickly re-setting controls after each test (and avoids needing to re-launch a new browser instance for each test cases – which makes it really fast).
You can quickly rip through hundreds or thousands of automated tests in seconds:
Green results mean the tests passed. Red results flag that a test case failed and log the assertion failure and/or runtime exceptions that occurred.
If you’ve ever struggled to try and come up with a strategy for doing automated unit testing or TDD with AJAX applications, I think you’ll find Silverlight provides some much nicer test options. Using Visual Studio you can also separate your tests into a separate project in your solution, and you do not need to embed the tests within your Silverlight application in order for them to run.
In addition to supporting the above unit test harness and framework, we are also going to support UI automation APIs with the final release of Silverlight 2. These will enable accessibility scenarios (allowing screen readers to work with Silverlight and enable Section 508 compliance of Silverlight applications). These UI automation APIs will also enable UI testing scenarios where you can build end to end browser UI automation that simulates real mouse and keyboard interactions and enables automated end to end experience testing. The combination should enable you to build much more solid and maintainable RIA solutions.
Hope this helps,
P.S. For more tutorial posts and links on Silverlight 2, check out my new "Silverlight Tips, Tricks, Tutorials and Links" page.