Windows Phone: Store unit test results to isolated storage

Posted on Mon 22 August 2011 in Technology • 1 min read

1
<p>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.</p>

Assuming you’ve Mango tools setup already. Get Mango compatible SL unit testing framework bits from Jeff’s blog.

Sample project is available here.

Setting it up..


- Add IsolatedStorageReportingProvider.cs to your test project -

Wire it up with the UnitTestHarness in your application entry page (see my MainPage.xaml.cs). By the way, Silverlight Unit Test framework code is available on codeplex. Feel free to explore :)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
</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 to get the results onto desktop

    Isetool

     

Additional thoughts


- With some ISETool.exe and MSBuild fu, it should be possible to get continuous integration magic. In this context, Richard Szalay‘s WP7CI 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 may be possible too. Looks like testresults.trx requires some additional files to work correctly in VS (could be because of vsmdi test metadata?)