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

  • Pingback: Dew Drop – May 28, 2010 | Alvin Ashcraft's Morning Dew

  • Pingback: Yesterday’s Good and Bad in Silverlight « greenicicle

  • Pingback: Elegant Code » StatLight V1.0 & V1.1 Released (Silverlight Testing Automation Tool)

  • Pingback: Windows Client Developer Roundup for May 31, 2010, Holiday Edition - Pete Brown's 10rem.net

  • Pingback: DotNetShoutout

  • Pingback: Trusting politicians and Silverlight

  • Brian

    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.

  • Pingback: NUnit for Silverlight, now with data driven tests « greenicicle

  • Jabba

    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.

  • http://www.jeff.wilcox.name/ Jeff Wilcox

    @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.

  • http://www.habanerolabs.com Mark Whitfeld

    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

  • http://www.jeff.wilcox.name/ Jeff Wilcox

    @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…

  • http://www.habanerolabs.com Mark Whitfeld

    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’)?

  • Pingback: A Cheat Sheet for Unit Testing Silverlight Apps on Windows Phone 7 | Smarty Pants Coding

  • Pingback: The best resources for Windows Phone 7 Development

  • http://www.virtual-remote.com Bert Lagaisse

    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

  • http://www.jeff.wilcox.name/ Jeff Wilcox

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

  • http://www.virtual-remote.com Bert Lagaisse

    @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

  • Paul Candido

    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

  • facy

    Hello Jeff,
    I would like to use your Unit Framework but unfortunatley Visual Studio throws an error while creating the testPage:

    XamlParseException occured
    Cannot find a Resource with the Name/Key typeNameConverter [Line: 47 Position: 24]

    Line 47 refers to the initial CreateTestPage:

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
    SystemTray.IsVisible = false;

    47: var testPage = UnitTestSystem.CreateTestPage() as IMobileTestPage;
    BackKeyPress += (x, xe) => xe.Cancel = testPage.NavigateBack();
    (Application.Current.RootVisual as PhoneApplicationFrame).Content = testPage;

    }

    Hope you can help me out!
    thank you!

  • Pkzphotos

    I’ve been struggling to get the framework to run in Express Edition or VS2010 and finally downloaded WP7UnitTestsSampleApp from http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7. That worked in both editions.

    Turns out the test project must be targe Windows OS 7.0 or you get:
    Cannot find a Resource with the Name/Key typeNameConverter [Line: 47 Position: 24]

    Happy coding.

  • rohan

    My App is 7.1. I am unable make the test project target Windows OS 7.0 and I get the same error, what do you recommend changing ?