Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a simple Silverlight unit test?

I'm looking to create some Silverlight unit tests. I've started by downloading the Silverlight Toolkit and looking at the unit tests there which are all built on the Silverlight Unit Testing Framework.

However it seems that the test class structure is quite complex in the source and I don't want to re-write the test classes defined in that package (e.g. ControlTest->FrameworkElementTest->TestBase->SilverlightTest inheritance chain is defined and only the last class is all defined in the Silverlight Toolkit).

I'm looking for a code sample of the simplest unit test implementation possible with the Silverlight Unit Test Framework (e.g. executing Assert.IsTrue(true)).

like image 427
Gergely Orosz Avatar asked Oct 22 '09 11:10

Gergely Orosz


People also ask

What is example unit test?

A unit test is a type of software test that focuses on components of a software product. The purpose is to ensure that each unit of software code works as expected. A unit can be a function, method, module, object, or other entity in an application's source code.

What are the three steps in a unit test?

The idea is to develop a unit test by following these 3 simple steps: Arrange – setup the testing objects and prepare the prerequisites for your test. Act – perform the actual work of the test. Assert – verify the result.


2 Answers

I'm surprised Jeff Wilcox didn't link to his own article!

This is the one that I used to set up my tests in Silverlight:

http://www.jeff.wilcox.name/2008/03/silverlight2-unit-testing/#option2

It was originally written for Silverlight 2, but I got it working under 3 with no issues.

like image 113
Chris Jaynes Avatar answered Oct 12 '22 23:10

Chris Jaynes


Just for information, Visual Studio 2010 beta 2 has Silverlight unit testing out of the box. Maybe you want to take a look.

like image 27
Konamiman Avatar answered Oct 13 '22 01:10

Konamiman