Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to: Create a Smart Device Unit Test

Visual Studio 2008

A smart device unit test is just a unit test created in a smart device test project. There are two ways to create unit tests in a smart device project. You can generate them from your production code, as described in the following procedure, and then edit them to work the way you want. Or, you can write unit tests by hand, as described inHow to: Create and Run a Unit Test.

Implementing Unit Tests

When you generate unit tests, one unit test method is created for each method of production code that you have selected in the Create Unit Tests dialog box. This process is explained in the following procedure. Each generated unit test calls the Inconclusive method, which causes the test to fail because the test is unimplemented. The next step is to implement the test by adding meaningful code that checks the correct operation of the method being tested.


Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To generate a unit test

  1. In Solution Explorer, right-click a smart device test project, point to Add, and then click Unit Test.

    - or -

    In Solution Explorer, right-click a smart device test project, point to Add, and then click New Test. In the Add New Test dialog box, click Unit Test Wizard, and then click OK.

    - or -

    In the Test View window, right-click the surface of the window and then click New Test. In the Add New Test dialog box, click Unit Test Wizard, and then click OK.


    To open the Test View window, on the Test menu, point to Windows, and then click Test View.

    - or -

    In the Visual Studio code editor, right-click a namespace, class or method that you want to test, and then click Create Unit Tests.

    This displays the Create Unit Tests dialog box.


    The Create Unit Tests dialog box does not support generating test methods from a device assembly. The Add Assembly button and dialog box do not work in smart device tests projects.

    A tree structure displays the class and member hierarchy of the assembly that houses your code. You can use this page to generate unit tests for any selection of those members or classes, and to select a project into which you want the generated unit tests to be included. The code elements that are first selected in the tree structure are the element that you right-clicked plus all child elements that it contains. The selection is based on the current cursor position.

  2. (Optional) Click Filter to change the contents of the displayed class and member hierarchy.

  3. (Optional) Select additional code elements by checking their boxes.

  4. (Optional) Click Settings to change configuration settings for this generation of tests. For example, you can change the default naming options for test files, classes, and methods to be generated. When finished, click OK.

  5. Click OK.

    If your solution does not already have a test project, this action creates a smart device test project and puts the test in the project. If the test project for your solution does not already have a file that contains a test class, this action creates one and opens the file. The class is populated with an Initialize() method, a Cleanup() method, and methods to test the code elements you selected in steps 1 and 2. Solution Explorer displays the new test file in your test project.

Community Additions

© 2015 Microsoft