Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight 5 VS 2012 Unit Tests

For last couple hours i have been trying to generate a Unit Test for a Silverlight application.

A number of posts refer to a "Silverlight Unit Test Project" which is part of the Silverlight Toolkit. But I downloaded the toolkit and still do not have the Test Project, it seems to be only available in VS 2010?

I have added a "Silverlight Class Library" project and added references to:

  1. Microsoft.Silverlight.Testing
  2. Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight

and the following TestClass:

using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTesting
{
    [TestClass]
    public class Class
    {

        [TestMethod]
        public void TestMethod()
        {
            .....    
        }
    }
}

But there are no tests being discovered by Visual Studio 2012 Test Explorer. Even after re-build of solution and restart of application.

Anyone have any ideas? Is this even possible?

like image 213
Michal Ciechan Avatar asked Mar 11 '13 15:03

Michal Ciechan


2 Answers

This link has the answer that worked for me:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/5e991b0d-8061-4c4e-a17d-82b4abd58d6c/vs-2012-silverlight-unittest

I recommend starting a new Silverlight project and installing the SilverlightToolkit-Testing NuGet package. In your test files, put in usings for Microsoft.Silverlight.Testing and Microsoft.VisualStudio.TestTools.UnitTesting and use regular [TestClass] and [TestMethod] attributes. To run them, you can use the Toolkit test runner by putting RootVisual = UnitTestSystem.CreateTestPage(); in your App.Application_Startup(), use Silverlight Unit Test Adapter (which currently is at v0.0.1 and doesn't really work), or (the best approach by far) install ReSharper and the AgUnit plugin.

like image 66
Keith Payne Avatar answered Sep 18 '22 14:09

Keith Payne


To complete this thread,

The Silverlight DLLS are located in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Testing

I could not get Resharper 7.1 to run the tests but this library helped. You will need to extract using 7-zip so that the DLLS are not blocked. Then restart Visual Studio 2012 and Resharper will run your unit tests.

like image 35
harryhazza Avatar answered Sep 20 '22 14:09

harryhazza