Updated Silverlight Unit Test Framework bits for Windows Phone and Silverlight 3

Here are updated quasi-official unit test framework bits for Silverlight 3 and Windows Phone developers. These are not intended for Silverlight 4 developers, since the same framework built for SL4 is included in the April 2010 Silverlight Toolkit.

This brings the new features from the Silverlight 4 version to developers who have a business reason to continue with Silverlight 3 development for the time being:

  • Updated user interface
  • Integrated “tag expression” support for selecting subsets of tests to run
  • Performance improvements
  • Removal of dependencies on XLinq and System.Windows.Browser assemblies

These are also the bits you want for Windows Phone testing.

Why wasn’t there one for Silverlight 3 already?

Since the April 2010 toolkit release was targeted for Silverlight 4 developers only, these bits were not released for version 3 (though were built from the same source).

Why doesn’t the April 2010 toolkit work for Windows Phone development & testing?

The Windows Phone development environment is based on a version of Silverlight 3 today, and so that means that you need to use Silverlight 3 binaries and class libraries when re-using Silverlight apps and code – not Silverlight 4.

These bits work well for phone developers and replace the older bits I had posted to my MIX talk site.

Download the binaries

[Silverlight 3 binaries for the Silverlight Unit Test Framework, Zip 452KB]
You may need to ‘unlock’ the binaries for security reasons once downloading and extracting the assemblies from the .Zip. To do this, right-click on the file and select the ‘Unlock’ button.

These binaries are strong named as before, but are not Authenticode signed, so they are not official. This helps work around some Windows Phone signing issues I’ve heard reports of.

Hope this helps,
Jeff

Comments

  1. May 28th, 2010 | 4:21 am

    [...] Updated Silverlight Unit Test Framework bits for Windows Phone and Silverlight 3 (Jeff Wilcox) [...]

  2. May 29th, 2010 | 1:35 am

    [...] Good news for guys like me who still have Silverlight 3 projects cooking is that Jeff Wilcox has ported the unit testing framework from the March 2010 Silverlight toolkit to Silver…- the latest release of the toolkit is only available for Silverlight 4. The obvious improvement is [...]

  3. May 30th, 2010 | 6:59 pm

    [...] I knew once I marked it 1.0, I would probably have updates to it & sure enough… Microsoft’s Jeff Wilcox released a new version of the Microsoft.Silverlight.Testing. [...]

  4. May 31st, 2010 | 11:30 pm

    [...] Updated Silverlight Unit Test Framework bits for Windows Phone and Silverlight 3 (Jeff Wilcox) [...]

  5. June 1st, 2010 | 10:03 am

    Updated Silverlight Unit Test Framework bits for Windows Phone and Silverlight 3 – Jeff Wilcox…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

  6. June 2nd, 2010 | 8:48 am

    [...] Silverlight Unit Test Framework updated for WinPhone7. [...]

  7. Brian
    June 7th, 2010 | 9:24 pm

    Thank you for your passion. very useful.

    I have a question.

    =========================================================================================

    I want to get the result file(.trx format) like Desktop Silverlight Unit Test Framework.

    How can i generating result file in my TestApp File System ?

    For desktop :

    I use ‘Visual Studio Command Prompt’. Generated ‘TestResult.trx’.

    ex) msbuild /t:coveragetest

    I want to report an other person for testing result.

    so..i want make like this App

    [1] MyTestApp of WP7 drop the result file.

    [2] Upload result file to Web Server.

    So, I need to result file.

    If UTF is not supported, i want to make this solution by reference SL3 UTF.

    Is that possible ?

    If possible, Where is the result making module source ?

    Please help me.

  8. June 10th, 2010 | 11:54 pm

    [...] for Silverlight. It supports NUnit 2.5.5 on Silverlight 3 and 4, and I’ve added support for Jeff Wilcox’ port of the April version of the Silverlight testing framework on Silverlight [...]

  9. Jabba
    June 11th, 2010 | 12:45 pm

    UI and test speed much improved, thanks. I do notice that the Test Stage doesn’t show anything added to the TestPanel unless I click on the splitter, then it updates and shows every time a test add something.

  10. June 15th, 2010 | 9:30 pm

    @Jabba,
    Yeah it’s a little inconsistent, it looks like there is a visual tree bug of some sort in the Silverlight plugin that is manifested in this sort of test stage situation. I’ve seen it on tests now, too.

  11. July 30th, 2010 | 1:06 am

    Hi Jeff
    Thanks for all the work you have done to make TDD for Silverlight at least a bit sane. I have been using your Silverlight Unit Test Framework with Silverlight 3 and did the conversions you mentioned earlier to get it running with nunit. The best thing is that I was able to run the tests from Resharper and from nunit-console.exe on my Hudson build server and display the test results :) I came across a problem with running tests that needed to be run on the UI Thread, but was able to work around it with the following class that I created:
    public static class UIThread
    {
    public static void Run(Action action)
    {
    Dispatcher dispatcher = TryGetInstance(() => Deployment.Current.Dispatcher)
    ?? TryGetInstance(() =>
    {
    PropertyInfo propertyInfo = typeof (Dispatcher).GetProperty(
    “MainDispatcher”, BindingFlags.Static | BindingFlags.NonPublic);
    return (Dispatcher) propertyInfo.GetValue(null, new object[] {});
    })
    ?? TryGetInstance(() => Application.Current.RootVisual.Dispatcher);
    if (dispatcher != null)
    {
    dispatcher.BeginInvoke(action);
    }
    else
    {
    SynchronizationContext synchronizationContext = TryGetInstance(() => SynchronizationContext.Current);
    if (synchronizationContext != null) synchronizationContext.Send(state => action(), null);
    else action();
    }
    }

    private static T TryGetInstance(Func func)
    where T : class
    {
    T instance = null;
    try
    {
    instance = func();
    }
    catch (Exception) { }
    return instance;
    }
    }

    This class was able to run the test on the UI thread in the test runner as well as in resharper and through nunit-console. My world was complete!
    Then I upgraded to SL4 and none of those dispatcher calls work any more when I am running the tests outside of your test runner. Most of the calls give an error about ‘agcore.dll’ is missing. This used to work in SL3.
    What would I need to do to get a dispatcher thread when running outside of the silverlight app? Any ideas? Is there some Silverlight initialisation call I can make?

    Thanks
    -Mark

  12. July 30th, 2010 | 1:09 am

    @Mark,
    So is this all running inside a Silverlight plugin or not? Since the framework has a dependency on System.Windows, even if that is pulled it, it may be trying to p/invoke into the platform (SL)’s native code, which is in agcore and nptctrl…

  13. July 30th, 2010 | 3:29 am

    Hi Jeff
    Thanks for your quick reply.
    It is not running inside a Silverlight plugin.
    It is basically just a Silverlight Unit Test Framework project where I have made all dlls copy local (except for mscorlib) and have used the nunit test framework (compiled for silverlight). I am then using the nunit-console test runner to run the nunit tests in the compiled dll of the project.
    The strange thing is that in SL3 when I used this code I would be able to access the dispatcher using at least one of the methods above, but in SL4 none of the methods work(they now give the ‘agcore’ missing error), and there doesn’t seem to be any dispatcher instance that I can access.
    Is there any way of instantiating the ui thread without having to run it inside the silverlight application environment (with a dependency on ‘agcore’)?

  14. August 6th, 2010 | 7:25 am

    [...] you'll need the Silverlight Unit Test Framework tweaked for Windows Phone 7 from Jeff Wilcox's blog here. I've attached the binaries to this post as well [...]

  15. August 16th, 2010 | 6:09 am

    [...] How to build a Windows Phone 7 app using test driven development – introduces concepts of unit testing for Windows Phone 7, contrary to the location given in the tutorial, you should locate the unit testing toolkit here [...]

  16. August 18th, 2010 | 3:54 pm

    Hi. I watched your MIX10 video on unittesting WP7. My tests stop running because I get Visual Studio breaking on exceptions in between my test project and tested projected (when the exception is thrown at the top level public method i’m testing. I tried to disable it in the debug -> exceptions list. But no luck.

    any ideas ?

    greets

    Bert Lagaisse

  17. August 18th, 2010 | 3:57 pm

    @Bert,
    This should be fixed in newer builds – what version of the phone tools are you using?

  18. August 23rd, 2010 | 6:17 am

    @Jeff: I am using the beta version in Visual Studio 2010 professional. The problem also occurs in the VS express version shipping with the beta tools.

    Furthermore a small suggestion: could the start window of the WP7 unit testing app show the tags found in the tests, so we can just click it ? Since the beta emulator, the phone onscreen keyboard must be used to type text, and that takes time. The computer keyboard can’t be used anymore.
    Oh, and I would also love a EnqueueConditionalWithTimeOut ;-)
    kind regards,
    Bert Lagaisse

  19. Paul Candido
    August 24th, 2010 | 7:39 pm

    Hi Jeff,

    Thanks for releasing this and for your continued support of Silverlight testing

    One problem I’ve found though…
    We have a continuous integration server which runs our SL tests using the msbuild command line and in some cases we have a need to use the tag expression which worked great in the November toolkit release
    Example:
    msbuild -t:test /p:tagexpression=TagToRun

    But this does not seem to work in the new version, I also tried setting the tag expression in the App.xaml.cs

    Example:
    UnitTestSettings settings = new UnitTestSettings();
    settings.TestAssemblies.Add(Assembly.GetExecutingAssembly());
    UnitTestSystem.SetStandardLogProviders(settings);
    settings.TestHarness = new UnitTestHarness();
    UnitTestSystem.SetTestService(settings);
    settings.TagExpression = “TagToRun”;
    this.RootVisual = UnitTestSystem.CreateTestPage(settings);

    Thanks in advance