Monday, 26 September 2011

Silverlight Testing Automation Tool

Unit testing out of the box with Silverlight is a real pain.  Luckily for us StatLight makes its a breeze and also provides continuous integration with Visual Studio and TeamCity.

My code below shows a nice example of an application using the MVVM Light framework.

How Does It Work?

StatLight is a console application that creates an in memory web server. It starts up a web browser that will request from the web server a page containing your test xap. By executing all the tests in the browser and communicating test results back to the web server. The console now has the ability to publish those results in manners not allowed in the Silverlight sandbox.

Visual Studio Integration (via ReSharper and AgUnit)


TeamCity Integration


TeamCity Configuration


Standard StatLight Console Output


Silverlight Test Project

Some interesting points about the Silverlight Unit Tests:

  • To use EnqueueCallback and EnqueueTestComplete you need to inherit from SilverlightTest, available within the Silverlight Toolkit SDK.
  • The method’s utilising these calls must be marked with the [Asynchronous] attribute.
  • You’ll often need to tailor your code to provide hooks for the unit tests.  For example adding an event after an action occurs so that TestMethod can subscribe to the event.



No comments:

Post a Comment