The Microsoft Test project template in Microsoft Visual Studio 2010 does not support adding a reference to a Silverlight class library. To unittest a function in a Silverlight class library you can follow the steps below:
– Install the Microsoft Silverlight Toolkit April 2010 (http://silverlight.codeplex.com/releases/view/43528)
– After installing the Microsoft Silverlight Toolkit April 2010, you can find a [Silverlight Unit Test Application] project template, under Installed Templates > Visual C# > Silverlight in the Add New Project wizard in Microsoft Visual Studio 2010.
– This will add 2 projects to your solution, a [test project] and a [test application] to run the Silverlight unittests in the browser.
– Add a reference in the [test project] to the Silverlight class library to test.
– Now you can run the unittest in a browser by starting the [test application]:
If you don’t want to run the silverlight unittests in the browser, but directly in Microsoft Visual Studio 2010, like normal unittests, follow the steps below:
– Install Jetbrains resharper
– Download the JetBrains Resharper plugin agunit [http://agunit.codeplex.com/]
– Create the folder [C:\Program Files (x86)\JetBrains\ReSharper\v6.0\Bin\Plugins\AgUnit] if it does not exist.
– Extract the agunit zip and add the contents to the folder: [C:\Program Files (x86)\JetBrains\ReSharper\v6.0\Bin\Plugins\AgUnit].
– Open your solution containing the Silverlight test project in Microsoft Visual Studio 2010 and click on the green circle next to your silverlight unittest:
You can now run your Silverlight unittest directly from Microsoft Visual Studio 2010
You can add only a Silverlight [test project], without the [test application] to a solution by unchecking the [Host the Silverlight application in a new or existing Web site in the solution] checkbox: