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)

ScreenShot142

TeamCity Integration

ScreenShot137

TeamCity Configuration

ScreenShot139

Standard StatLight Console Output

ScreenShot141

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.

ViewModel

Downloads

http://statlight.codeplex.com

http://agunit.codeplex.com

http://stevenhollidge.com/blog-source-code/SilverlightUnitTestDemo.zip

No comments:

Post a Comment