How to: Create and Configure Test Projects for Automated Tests
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 can 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.
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.
Configure test project creation. Set the programming language for new test projects, and whether one or more tests should be added to new test projects by default.
To 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.
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 on the Tools menu.
In the Templates pane, select the type of test that you want to add.
The New Test Project dialog box is displayed.
Enter a name for the new test project, or accept the default name, and then click Create.
Depending on the type of test that 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.
To create a test project as you generate unit tests
Open a source-code file.
Right-click a namespace, class, or method.
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.
The New Test Project dialog box is displayed.
Type a name for the new test project, or accept the default name, and then click Create.
The test project is added to your solution together with the new unit test.
To create a test project by using the Add New Project dialog box
In Solution Explorer, right-click the solution.
Point to Add and then 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.
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 that you are about to add.
The test project is added to your solution.
Configure Test Project Creation
To configure test project creation
On the Tools menu, click Options.
The Options dialog box is displayed.
Expand Test Tools in the left pane and then click Test Project.
(Optional) Under Default test project language, choose a programming language for new test projects.
(Optional) You might want to make sure that your test project and the project that contains your code under test use the same language. If you do want them to use the same language, select the check box When automatically creating a test project, disregard the default language setting and use the language of the production-code project instead.
(Optional) You can choose to enable a feature that will cause your Test List and Test View windows to update automatically when you make changes to methods instead of having to click Refresh manually. Doing this has been known to cause some performance problems and other issues with VSMDI files. To enable this feature, clear the Disable background discovery of test methods check box.
Under Select the files that will be added to each new test project, by default, choose, by language, the type of test project that you want to configure.
Select the tests that you want added to test projects of the selected language as those projects are created.
You can select zero tests. If you do select zero tests, each new test project is empty. This means that it contains, for example, a property page and a reference to a namespace, but no tests or source-code files. You can add tests later through the Add New Test dialog box.
(Optional) Repeat steps 4 and 5 for test projects in different languages.
The settings are stored for use the next time that you create a test project.
You can change these preferences at any time, before you create additional test projects.