This documentation is archived and is not being maintained.

How to: Create a Test Project

Test projects can contain tests of any type. You can create a test project explicitly. Or, if your solution contains no test projects when you create your first test, a test project is created automatically and the test is placed in it.

Before you create a test project, you may choose to configure the way test projects are created. This means determining how many tests and what kinds of tests are automatically added to new test projects, as well as the language of the test project. To do this, you use the Options dialog box, reached from the Tools menu. For more information, see How to: Configure Test Project Creation.

As described in the following procedures, you can create test projects in several ways:

  • Create a test project when you add a test. When you create a new test, you can create new a test project into which the test will be added, or add the test to an existing test project.

  • Create a test project when you generate a unit test. When you generate unit tests, you can create a new test project into which the tests will be added, or add them to an existing test project.

  • Using the Add New Project dialog box. With this method, you can choose the programming language of your test project, which might be important if you plan to code tests, such as in unit tests or coded Web tests.

Create a test project when you add a test

  1. Click Test and then click New Test.

    The Add New Test dialog box is displayed.

  2. Under Add to Test Project, choose one of the options for creating a new test project. For example, click Create a new Visual C# Test Project.

    NoteNote

    The type of test project shown by default under Add to Test Project is the type that is currently set as the default in the Options dialog box reached through the Tools menu. For more information, see How to: Configure Test Project Creation.

  3. In the Templates pane, select the type of test you want to add.

  4. Click OK.

    The New Test Project dialog box appears.

  5. Enter a name for the new test project, or accept the default name, and click Create.

  6. Depending on the type of test you chose, you are now given the opportunity to code or generate the newly added test.

The test project and the test it contains are added to your solution.

Create a test project as you generate unit tests

  1. Open a source-code file.

  2. Right-click a namespace, class, or method. For more information on creating new unit tests, see How to: Generate a Unit Test.

  3. Click Create Unit Tests.

    The Create Unit Tests dialog box is displayed.

  4. (Optional) Change the selection of members for which you want to generate unit tests.

  5. Under Output project, choose one of the options for creating a new test project. For example, click Create a new Visual C# Test Project.

  6. Click Generate.

    The New Test Project dialog box is displayed.

  7. Enter a name for the new test project, or accept the default name, and click Create.

The test project is added to your solution along with the new unit test.

Create a test project using the Add New Project dialog box

  1. In Solution Explorer, right-click the solution.

  2. Point to Add and click New Project.

    The Add New Project dialog box is displayed. The Project types pane contains a Test Projects node and nodes for specific programming languages.

  3. If you want your new test project to have a specific programming language, expand the node of that language; if not, expand Test Projects.

    NoteNote

    Test projects are not available in every language.

  4. If you expanded a language node, click Test. If you expanded the Test Projects node, click Test Documents.

  5. Under Templates, click Test Project.

  6. (Optional) Change the name or location of the project you are about to add.

  7. Click OK.

The test project is added to your solution.

See Also

Show: