Unit testing templates for Microsoft Silverlight 2 Beta 2

Posted 6 June 2008  

The unit test framework binaries that we released for Silverlight 2 Beta 1 work just fine with Silverlight 2 Beta 2, that was just released today.  However with the updated project file format for Beta 2, I've gone ahead and prepared updated templates that you should download and install.  There's no need at this time to upgrade the actual test framework binaries.

Introducing Visual Basic test project templates for Beta 2

This was a big ask previously.  Today I'm providing both C# and VB project templates.

Download updated Visual Studio test project templates for Beta 2

To simplify adding test projects and classes to your .NET Silverlight applications and class libraries, these templates will quickly add a new test project and wire up the test framework so that you can right-click, set the StartUp project, and run the tests. Unit test project template for Silverlight 2 Beta 2 C#: Download VB: Download To install: save this file into your “%userprofile%\Documents\Visual Studio 2008\Templates\ProjectTemplates” directory Test class item template for Silverlight 2 Beta 2 C#: Download VB: Download To install: save this into “%userprofile%\Documents\Visual Studio 2008\Templates\ItemTemplates”

Upgrading your existing Silverlight 2 unit test projects

With the change to the Application::RootVisual property in Beta 2, the CreateTestPage return value needs to be cast to UIElement for updated test projects to compile. Here's how to update your existing C# test projects:
  1. Open your existing Silverlight unit test project application project in Visual Studio after installing Beta 2
  2. Perform an upgrade when prompted by Visual Studio
  3. Open the App.xaml.cs file
  4. Navigate to the Application_Startup method
  5. Modify the RootVisual line by inserting "(UIElement) " before the call to UnitTestSystem.CreateTestPage.
Here's what the updated Application_Startup line should look like:

private void Application_Startup(object sender, StartupEventArgs e)

{

    // Hook up and execute this test project

    this.RootVisual = (UIElement)UnitTestSystem.CreateTestPage(this);

}

What's next

Now that Beta 2's out there, on the test front you can expect in the coming weeks:
  • Updated drop of the Microsoft.Silverlight.Testing binaries with a small set of bug fixes and updated features
  • Simple continuous integration support (Team Foundation Build and CruiseControl.NET)
  • Test run reporting and perhaps some other surprises
Hope this helps!

Jeff Wilcox is a Principal Software Engineer at Microsoft in the Open Source Programs Office, helping Microsoft scale to 10,000+ engineers using, contributing to and releasing open source.

comments powered by Disqus