Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Walkthrough: Creating and Running Unit Tests for Windows Store Apps


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at Walkthrough: Creating and Running Unit Tests for Windows Store Apps.

Visual Studio includes support for unit testing managed Windows 8.x Store apps and includes unit test library templates for Visual C#, Visual Basic and Visual C++.

System_CAPS_ICON_tip.jpg Tip

For more information about developing Windows 8.x Store apps, see Getting started with Windows Store apps.

Visual Studio provides the following unit testing functionality:

The following procedures describe the steps to create, run and debug unit tests for managed Windows 8 Windows 8.x Store app.

Visual Studio

To create a unit test project for a Windows Store app

  1. From the File menu, choose New Project.

    The New Project dialog displays.

  2. Under Templates, choose the programming language you want to create unit test in and then choose the associated Windows 8.x Store unit test library. For example, choose Visual C# , then choose Windows Store, and then choose Unit Test Library (Windows Store apps).

    System_CAPS_ICON_note.jpg Note

    Visual Studio includes unit test library templates for Visual C#, Visual Basic and Visual C++.

  3. (Optional) In the Name textbox, enter the name you want to use for the Windows 8.x Storeunit test project.

  4. (Optional) Modify the path where you want to create the project by entering it in the Location textbox, or choosing the Browse button.

  5. (Optional) In the Solution name textbox, enter that name you want to use for your solution.

  6. Leave the Create directory for solution option selected and choose the OK button.

    Tailored Unit Test Library

    Solution Explorer is populated with your new Windows 8.x Storeunit test project and the code editor displays the default unit test titled UnitTest1.

    New tailored unit test project

It may be necessary to edit the manifest for the unit test project to provide required capabilities to run the app.

To edit the unit test project’s Windows Store application manifest file

  1. In Solution Explorer, in the new Windows 8.x Store unit test project, right-click the Package.appxmanifest file and choose Open.

    The Manifest Designer displays for editing.

  2. In the Manifest Designer, choose the Capabilities tab.

  3. In the list under Capabilities, select the capabilities that you need your unit test and the code that it testing to have. For example, select the Internet checkbox if the unit test needs and the code it is testing need to have the capability to access the internet.

    System_CAPS_ICON_note.jpg Note

    The capabilities you select should only include capabilities that are necessary for the Windows 8.x Store unit test to function correctly. The capabilities should never have to include capabilities that are not part of the Windows 8.x Store app being tested and generally should be a subset of the capabilities specified for the Windows 8.x Storeapp under test.

    For more information about the Manifest Designer, see Configure a Windows 8.1 app package by using the manifest designer.

    Unit Test Manifest

To code the unit test for a Windows Store app

  1. In the Code Editor, edit the unit test and add the asserts and logic required for your test.

    For more information, see in Using the Assert Classes in the MSDN library.

To build the solution and run the unit test using Test Explorer

  1. On the Test menu, choose Windows, and then choose Test Explorer.

    Test Explorer displays without your test being listed.

  2. From the Build menu, choose Build Solution.

    Your unit test is now listed.

    System_CAPS_ICON_note.jpg Note

    You must build the solution to update the list of unit tests in Test Explorer.

    System_CAPS_ICON_warning.jpg Warning

    Visual Studio known issue: You must open Test Explorer prior to building the test project.

  3. In Test Explorer, choose the unit test you created.

    System_CAPS_ICON_tip.jpg Tip

    Test Explorer provides a link to the source code next to Source:.

  4. Choose Run All.

    Unit Test Explorer - run unit test

    System_CAPS_ICON_tip.jpg Tip

    You can select one or more unit tests listed in Explorer and then right-click and choose Run Selected Tests.

    Additionally, you can choose to Debug Selected Tests, Open Test, and use the Properties option.

    Unit Test Explorer - uni test context menu

    The unit test runs. Upon completion, Test Explorer displays the test status, elapsed time and provides a link to the source.

    Unit Test Explorer - test completed


Channel 9: Unit testing your Windows Store apps built using XAML


Visual Studio Unit Testing

MSDN Library

MSDN Library – Creating and Running Unit Tests for Existing Code (Visual Studio 2010)

Testing Store apps with Visual Studio
Build and test a Windows Store app using Team Foundation Build

© 2018 Microsoft