Wednesday, September 16, 2009

Silverlight Unit test Framework - running only one test class

One thing that can be a bit frustrating when developing Unit Tests for Silverlight using the Silverlight Unit Test Framework is that there is no explicit way (in the documentation) to isolate a specific set of tests to execute, sicne by default the test runner will execute all tests in the test assembly.

Fortunately, we can pass TagExpression's to our UnitTestSystem upon initialization, this will tell the system to only execute the tests in the classes indicated in this expression, as a comma separated list:

In App.xaml.cs, red text is the new code, where ClassWithTestsOfInterest is the test class that you want executed:

private void Application_Startup(object sender, StartupEventArgs e)
  {
 
var testsToRun = UnitTestSystem.CreateDefaultSettings();
  testsToRun.TagExpression = "ClassWithTestsOfInterestTests";

  this.RootVisual = UnitTestSystem.CreateTestPage(testsToRun);
  }