Notes on seeking wisdom and crafting software

Windows Phone: Store unit test results to isolated storage

This is a tiny experiment to automate parts of unit testing in Windows Phone 7.5 (Mango, here onwards). We will extend silverlight unit testing framework to store the results of a Mango unit test in MSTest test results format in application Isolated Storage and finally fetch them onto desktop.

Assuming you've Mango tools setup already. Get Mango compatible SL unit testing framework bits from Jeff's [blog](http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/).

Sample project is available [here](https://github.com/codito/wpsamples/tree/master/SLUnitTest.IsoStore).

Setting it up.. ---------------

- Add [IsolatedStorageReportingProvider.cs](https://github.com/codito/wpsamples/blob/master/SLUnitTest.IsoStore/PhoneApp.Test/IsolatedStorageReportingProvider.cs) to your test project -

Wire it up with the UnitTestHarness in your application entry page (see my [MainPage.xaml.cs](https://github.com/codito/wpsamples/blob/master/SLUnitTest.IsoStore/PhoneApp.Test/MainPage.xaml.cs)). By the way, Silverlight Unit Test framework [code](http://silverlight.codeplex.com/SourceControl/changeset/view/69081#976050) is available on codeplex. Feel free to explore :)
</p>
<div class="CodeRay">

</p>
<div class="code">

</p>
    // Set custom log writerIsolatedStorageReportingProvider isoLog = new IsolatedStorageReportingProvider(((MobileTestPage)testPage).UnitTestHarness.Settings.TestService);((MobileTestPage)testPage).UnitTestHarness.Settings.TestService.RegisterService(Microsoft.Silverlight.Testing.Service.TestServiceFeature.TestReporting, isoLog);// Uncomment this to automatically terminate the test application after test is complete!//isoLog.LogPublished += new EventHandler(this.OnTestHarnessCompleted);(Application.Current.RootVisual as PhoneApplicationFrame).Content = testPage;

</div>

</p>
<p>

</div>

</p>
<p>
  • Fire up [ISETool.exe](http://msdn.microsoft.com/en-us/library/hh286408.aspx) to get the results onto desktop

    [![Isetool](http://arun.files.wordpress.com/2011/08/isetool-scaled1000.png?w=300)](http://arun.files.wordpress.com/2011/08/isetool-scaled1000.png)

     

Additional thoughts -------------------

- With some ISETool.exe and MSBuild fu, it should be possible to get continuous integration magic. In this context, [Richard Szalay](http://blog.richardszalay.com/2011/08/11/wp7-tdd/)'s [WP7CI](http://wp7ci.codeplex.com/) project looks promising. I haven't tried it, may be it is possible to reuse the same set of scripts. - Publishing these [results to TFS servers](http://msdn.microsoft.com/en-us/library/ms182488.aspx) may be possible too. Looks like *testresults.trx* requires some additional files to work correctly in VS (could be because of vsmdi test metadata?)