Unit Testing Silverlight in Four Easy Steps Using TestComplete
Silverlight is a powerful Rich Internet Application (RIA) platform. There are many Silverlight web applications in use today (Netflix, anyone?), and now may be the best time for Silverlight unit test automation.
Now, wait a minute. Silverlight? Isn’t that technology going away? The short answer: Not really. Silverlight may be losing the battle with Flash as a browser plug-in, and both technologies may give way to HTML5 as the preferred technology for cross-platform delivery of rich content via browsers (status July 2012). However, the Silverlight foundation in the form of XAML is alive and well (and at home) on Windows 8.
Unit Testing Silverlight with TestComplete
Did you know that you can integrate your Silverlight unit tests into TestComplete test suites? You can run them together with your automated GUI tests to improve your continuous build and test process. If you’re interested in automating unit testing for Silverlight with TestComplete here’s what you will need to make the integration happen:
Ingredients:
- Silverlight 4, or 5. The latter can be 32-bit, or 64-bit.
- TestComplete 9.
Cooking Time: Around 30 minutes, depending on your scripting experience.
Preparation: TestComplete is the award winning and user-friendly recording and playback automated testing tool with extensive support for Silverlight. In addition to that support, TestComplete is also a powerful testing platform. It provides access to internal Silverlight objects, properties and methods. The following steps show how to take advantage of TestComplete insight into Silverlight for the purpose of Silverlight unit test automation.
Step 1: Write unit tests in your preferred environment. This can be Visual Studio, or any other editor you use for your .NET development. You can find an example Silverlight function and the associated unit tests in the following package: Name Extractor (Silverlight Application under Test).
Step 2: Create a new test in TestComplete, launch the test application and in the Object Browser in TestComplete locate the Silverlight root object called Object(0). This special Silverlight object exposed by TestComplete provides you with access to all the Silverlight application and unit tests objects, methods and properties that are needed for automation.
Step3: Get a handle to your unit test driver from within TestComplete.
Step 4: Now you have access to the unit tests and you can include them in a TestComplete script that can be scheduled to run together with the other UI tests.
Are you developing and testing Silverlight applications? Please share your thoughts and experiences in the comments below.