Compartilhar via


How to: Create a Basic Unit Test

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Visual Studio 2010 provides a variety of ways to create unit tests. The Basic Unit Test template is recommended for people who want to create a unit test with little assistance and for those creating unit tests for test-driven development. You can create a Basic Unit test using C++, C#, or Visual Basic.

Important

To create unit test for a C++ project, you must compile the project with the /clr:safe option. The /clr:safe option can be configured in the C++ projects Property Pages in the Configuration Properties node, under Project Defaults, in the Common Language Runtime Support drop-down list box. For more information, see Pure and Verifiable Code (C++/CLI).

If you want more assistance creating unit tests for existing code, see How to: Create and Run a Unit Test. For information about how to create unit tests for assemblies for which you do not have access to the code, see How to: Create a Unit Test without Source Code.

To create a basic unit test

  1. On the Test menu click New Test.

  2. In the Add New Test dialog box, click Basic Unit Test.

  3. In the Test Name text box, type a name for the test.

  4. Do one of the following:

    • To add a basic unit test to an existing test project, select the project in the Add to Test Project box and click OK.

      A new test class file that contains one blank test method is added to the test project.

    • To create a new test project for your unit test, choose a programming language in the Add to Test Project box and then click OK.

      Note

      If your solution contains several test projects you might have to scroll to locate the languages.

      The new test project is added to you solution with a blank test class that contains one blank test method.

      For more information about how to fill in the unit tests, see How to: Create and Run a Unit Test.

See Also

Concepts

Anatomy of a Unit Test

Creating and Running Unit Tests for Existing Code