Unit Testing Logs in WP7 application testing

China☆狼群 提交于 2020-01-15 04:01:06

问题


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 application 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


回答1:


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.



来源:https://stackoverflow.com/questions/7510029/unit-testing-logs-in-wp7-application-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!