This is a mirror of official site: http://jasper-net.blogspot.com/

Unit testing in Silverlight

| Monday, January 31, 2011
My team is working on a Silverlight project for the last three months. One of the first issues we encountered was unit testing for the Silverlight libraries.

Unfortunately, this issue is not trivial. Current dev tools, including the VSTS do not support running tests in the traditional way. In order for a Silverlight test to run, it needed to be hosted inside a web page. This is quite problematic when trying to practice TDD and even running the tests on your CI server.

Let's start at the beginning:

The Silverlight Sdk (aka Silverlight tools), contains a project type for Silverlight tests. Simply click New –> Project –> Silverlight and select Silverlight Unit testing Application:

image_thumb_57AD4301.png

As I mentioned before, Silverlight unit tests can only be run under a host web site, so after creating the project, Visual Studio will ask you to create a web site to host the tests.

In the unit testing project, a class will be created with the familiar VSTS test class:

[TestClass]
public class Tests
{
   [TestMethod]
   public void TestMethod1()
   {
       var c = new Class1();

       var result = c.Test();

       Assert.IsTrue(result);
   }
}

Read more: YsA.Net

Posted via email from Jasper-net

0 comments: