{"id":3543,"date":"2013-01-31T02:25:00","date_gmt":"2013-01-31T02:25:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/01\/31\/windows-phone-unit-tests-in-visual-studio-2012-update-2\/"},"modified":"2022-07-21T01:06:19","modified_gmt":"2022-07-21T09:06:19","slug":"windows-phone-unit-tests-in-visual-studio-2012-update-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/windows-phone-unit-tests-in-visual-studio-2012-update-2\/","title":{"rendered":"Windows Phone Unit Tests in Visual Studio 2012 Update 2"},"content":{"rendered":"<p>Unit Testing is an important part of the application development life cycle for any platform. Visual Studio users no longer need to depend on 3<sup>rd<\/sup> party frameworks for unit tests on Windows Phone. The Windows Phone Unit Test framework delivered in CTP2 of Visual Studio Update 2 provides a consistent experience for developers to author, run and debug tests for Windows Phone 8 platform. This article walks you through the steps to start unit testing on Windows Phone.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<ol>\n<li>Visual Studio 2012 <\/li>\n<li><a href=\"https:\/\/dev.windowsphone.com\/en-us\/downloadsdk\" target=\"_blank\" rel=\"noopener\">Windows Phone SDK 8.0<\/a> <\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=36508\" target=\"_blank\" rel=\"noopener\">Visual Studio 2012 Update 2 CTP 2<\/a> <\/li>\n<\/ol>\n<p>Note: You need a 64 bit Windows 8 physical machine (with Hyper-V enabled) to run unit tests on Windows Phone Emulator.<\/p>\n<p><strong>One Framework \u2013 Multiple Platforms<\/strong><\/p>\n<p>You can now write Unit Tests for Windows Phone in C# by creating a new \u201cWindows Phone Unit Test App\u201d project under Visual C#\/Windows Phone. Tests are executed on the target device by installing the Unit Test app on the phone.<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/7215.image_thumb_08796E47.png\" width=\"628\" height=\"389\" \/><\/p>\n<p><em>Figure 1: New Windows Phone Unit Test Template<\/em><\/p>\n<p>Whether you are writing classic unit tests, Windows Store unit tests, or Windows Phone unit tests \u2013 Visual Studio automatically adds all the necessary references and you are ready to start writing tests using the familiar MS Test framework. You no longer need to learn multiple frameworks to author unit tests for different platforms.<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/0434.image_thumb_4409573A.png\" width=\"628\" height=\"164\" \/><\/p>\n<p><em>Figure 2: Author tests using MSTest framework<\/em><\/p>\n<p><strong>Running Tests from Visual Studio<\/strong><\/p>\n<p>The Phone UT framework is designed as an adapter on top of the extensible Visual Studio 2012 unit testing platform (similar to other adapters like nUnit, xUnit). With this, the whole Visual Studio Test Driven Development experience is now extended to Windows Phone. Tests are discovered and displayed in the familiar Test Explorer window. Right from within the IDE, users can group\/filter tests using traits, turn on continuous test runner to view test results after each build, and debug or run selected (or failed) set of tests.<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n<tbody>\n<tr>\n<td>\n<p>\n          <em><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/0743.clip_image001_thumb_35120253.png\"><img decoding=\"async\" title=\"clip_image001\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"clip_image001\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/0743.clip_image001_thumb_35120253.png\" width=\"213\" height=\"223\" \/><\/a><\/em><em><\/em>\n        <\/p>\n<p>\n          <em>Figure 3: Phone Unit Tests discovered<\/em>\n        <\/p>\n<\/td>\n<td>\n<p>\n          <a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/6201.clip_image002_thumb_51CB7768.png\"><img decoding=\"async\" title=\"clip_image002\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/6201.clip_image002_thumb_51CB7768.png\" width=\"244\" height=\"125\" \/><\/a>\n        <\/p>\n<p>\n          <em>Figure 4:Set Target Device <\/em>\n        <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Visual Studio uses the target device set on the Run palette to install the unit test app, run tests, and return results. Supported targets include Emulators (only available when Hyper-V is enabled) and Windows Phone 8 devices physically connected to the machine. Developers can author, run, and debug tests on any of the target devices without leaving the IDE. While unit tests are running on the device, a &#8216;Tests Running&#8217; screen will be shown.<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/0728.image_thumb_55891C38.png\" width=\"214\" height=\"379\" \/><\/p>\n<p>*Figure 5: Unit Tests running on device**** ***<\/p>\n<p>**Running Tests from Command Line **<\/p>\n<p>As I mentioned earlier, since Phone UT is designed as an adapter to unit testing platform, you can use <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/vstudio\/jj155796.aspx\">vstest.console.exe<\/a> to execute unit tests from command line. You can also choose to export the results to Visual Studio Test Results File using <strong>\/Logger:trx<\/strong>.<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/8726.image_thumb_7C93B5AD.png\" width=\"672\" height=\"366\" \/><\/p>\n<p>*Figure 6: Run tests from command line**** ***<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/2860.image_thumb_180891E4.png\" width=\"724\" height=\"368\" \/><\/p>\n<p>*Figure 7: Test Results from TRX logger**** ***<\/p>\n<p>By default Emulator WVGA 512MB is the target device to execute tests, use <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/jj635153.aspx\">run settings<\/a> to change target device (Sample run settings attached).<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/01\/6266.image_thumb_741FBA89.png\" width=\"352\" height=\"129\" \/><\/p>\n<p><em>Figure 8: Run Settings to set target device<\/em><\/p>\n<p><strong>FAQs and Known Issues<\/strong><\/p>\n<ul>\n<li>Phone Unit Test does not support data collectors either on the physical device or emulator. <\/li>\n<li>Can I write unit tests in native C++?<br \/>\nIn CTP2 only C# is supported. VB# and C++ are not supported for now. <\/li>\n<li>Which versions of Windows Phone is supported?<br \/>\nYou can only author unit tests for apps that target Windows Phone 8. Windows Phone 7, 7.5, 7.8 are not supported. <\/li>\n<li>Which Visual Studio SKUs do I need to enable this feature?<br \/>\nWindows Phone Unit Tests works on all editions &#8211; Express, Test Professional, Professional and Ultimate. <\/li>\n<li>After installing all the prerequisites, I still do not see Windows Phone Unit Test template<br \/>\nWorkaround: Install the mentioned prerequisites in the specified order, all on the system drive <\/li>\n<li>Device was disconnected or interrupted while unit tests were in progress, what do I do?<br \/>\nWorkaround: When a device is disconnected or interrupted (for example, by an incoming call or the camera button), the test run fails and vstest may crash. Manually uninstall all the unit test applications from the device, reconnect the device, and try running tests again. <\/li>\n<li>I get an error message while debugging unit tests.<br \/>\nWorkaround: Manually stop the debugging session at the end of a test run and start debugging selected tests again. <\/li>\n<li>Phone Unit Tests that have a native dependency cannot be run from command line <\/li>\n<li>After Test Runs are complete, I sometimes still see Unit Test applications installed on device<br \/>\nWorkaround: Manually uninstall all the unit test applications from the device.<\/li>\n<li>Known Issue: Users who have a non English version of Windows Phone SDK Tools 8.0 will not be able to create new Windows Phone Unit Test projects.<\/li>\n<li>Known Issue: When a test fails, the stack trace does not contain line numbers indicating where the test failed, and users cannot navigate to code from stack trace information.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/MSDNBlogsFS\/prod.evol.blogs.msdn.com\/CommunityServer.Components.PostAttachments\/00\/10\/38\/98\/68\/phone-tests.runsettings\">phone-tests.runsettings<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unit Testing is an important part of the application development life cycle for any platform. Visual Studio users no longer need to depend on 3rd party frameworks for unit tests on Windows Phone. The Windows Phone Unit Test framework delivered in CTP2 of Visual Studio Update 2 provides a consistent experience for developers to author, [&hellip;]<\/p>\n","protected":false},"author":95,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"acf":[],"blog_post_summary":"<p>Unit Testing is an important part of the application development life cycle for any platform. Visual Studio users no longer need to depend on 3rd party frameworks for unit tests on Windows Phone. The Windows Phone Unit Test framework delivered in CTP2 of Visual Studio Update 2 provides a consistent experience for developers to author, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/95"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=3543"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3543\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=3543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=3543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=3543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}