views:

52

answers:

1

I am currently working on a project that uses the Silverlight 3 SDK and I want to create unit tests for my Silverlight code. I want these tests to not have to run in a browser context. I have referenced the Silverlight Unit Testing binaries that come in the SDK (Microsoft.Silverlight.Testing and Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight) which gives me the framework necessary to write the tests (the test attributes are present).

The issue I am currently running into is that the unit tests in Silverlight are not being recognized by any test runners. Test-Driven.NET will only run the most basic of unit tests (i.e. no TestInitialize method) and Visual Studio 2010's test runner does not perceive any tests to run at all. For example, even this simple unit test will not run:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SlUnitTests
{
    [TestClass]
    public class Class1
    {
        [TestMethod]
        public void Test1()
        {
            Assert.Fail();
        }
    }
}

Any ideas?


Edit:

I forgot to mention that this project was originally a Visual Studio 2008 project. I had these unit tests for Silverlight in VS2008 using the same Silverlight 3 SDK and they ran just fine. Both the ReSharper test runner and MSTest on the command line were able to run the Silverlight-based unit tests - no browser context was required. The Silverlight unit tests broke when my project was converted to VS2010. Sorry for the confusion.

A: 

Unfortunately there's no easy integration into the standard (non-browser) interface using these assemblies.

One option if you need to exercise basic code (no user interface code; nothing that uses System.Windows), you could create a proper class library and/or test project for full .NET in Visual Studio, and then "link" in the source files from your Silverlight project.

Jeff Wilcox
Does this apply to Visual Studio 2008 and 2010? I edited my question after getting a comment to include that I got this technique to work in Visual Studio 2008. Both ReSharper's test runner and MSTest would run Silverlight-based unit tests outside of a browser context.
avanek