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, in addition to the default language of the test project. To do this, you use the Options dialog box, which is available on 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 that is already loaded.
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 use a dialog box to choose the programming language of your test project.
Note
Smart device test projects cannot be created using the Add New Project dialog box.
Create a Test Project When You Add a Test
Create a test project when you add a test
Click Test and then click New Test.
The Add New Test dialog box is displayed.
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.
Note
By default, the type of test project shown under Add to Test Project is the type that is currently set as the default in the Options dialog box, which is available onthe Tools menu. For more information, see How to: Configure Test Project Creation.
In the Templates pane, select the type of test you want to add.
Click OK.
The New Test Project dialog box appears.
Enter a name for the new test project, or accept the default name, and click Create.
Depending on the type of test you chose, you can either hand-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
Create a test project as you generate unit tests
Open a source-code file.
Right-click a namespace, class, or method. For more information about how to create new unit tests, see How to: Create and Run a Unit Test.
Click Create Unit Tests.
The Create Unit Tests dialog box is displayed.
(Optional) Change the selection of members for which you want to generate unit tests.
Under Output project, choose one of the options for creating a new test project. For example, click Create a new Visual C# Test Project.
Click Generate.
The New Test Project dialog box is displayed.
Enter a name for the new test project, or accept the default name, and click Create.
The test project is added to your solution together with the new unit test.
Create a test project by using the Add New Project dialog box
Create a test project by using the Add New Project dialog box
In Solution Explorer, right-click the solution.
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.
If you want your new test project to have a specific programming language, expand the node of that language; if not, expand Test Projects.
Note
Test projects are not available in every language.
If you expanded a language node, click Test. If you expanded the Test Projects node, click Test Documents.
Under Templates, click Test Project.
(Optional) Change the name or location of the project you are about to add.
Click OK.
The test project is added to your solution.
See Also
Tasks
How to: Configure Test Project Creation
Concepts
How to: Create and Run a Unit Test