开发者

Unit Testing Logs in WP7 application testing

I m using Silverlight Unit Test framework for testing my application. The unit testing framework gets executed successfully and displays the result in the phone application page. I would like to get the results stored in a log file inside the device itself instead of displaying it on the phone applic开发者_C百科ation page on the device. Please find the image below which shows the results displayed for an application

http://www.jeff.wilcox.name/wp-content/uploads/2010/03/SilverlightUnitTestFrameworkforWindowsPhone1_thumb.jpg

Please suggest if there is any way to do it.

Thanks, Mugu


As far as I know the results are not stored in a log, but you can get access to the results.

From within the unit test's MainPage.xaml.cs you can hook into the TestHarness's TestHarnessCompleted event to get details about the completed test run. You can then format your output as required, and save to IsolatedStorage or/and transfer off the device.

//inside MainPageLoad()
var unitTestSettings = UnitTestSystem.CreateDefaultSettings();
unitTestSettings.TestHarness.TestHarnessCompleted += TestRunCompletedCallback;
var testPage = UnitTestSystem.CreateTestPage(unitTestSettings) as IMobileTestPage;

void TestRunCompletedCallback(object sender, TestHarnessCompletedEventArgs e) {
    var testHarness = sender as UnitTestHarness;
    foreach (var result in testHarness.Results) {
        switch (result.Result) {
            case TestOutcome.Passed:
            case TestOutcome.Completed:
                break;
            default:
                // must be a failure of some kind
                // perform some outputting
                break;
         }
    }
}

I think I read somewhere that there may be ways of transferring files programmatically from IsolatedStorage onto your desktop. I instead format the test results to a String and then use NLog to send that output to a listening service running on my desktop/buildserver. The full source NLog download provides a Visual Studio sample project for creating and running this sevice.

Cheers, Al.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜