|
1 | 1 | ---
|
2 |
| -title: Create a unit test project |
| 2 | +title: Create a Unit Test Project |
3 | 3 | description: Learn how to create a unit test project. The test project can be in the same solution as the production code, or it can be in a separate solution.
|
4 |
| -ms.date: 02/22/2023 |
| 4 | +ms.date: 04/17/2025 |
5 | 5 | ms.topic: how-to
|
6 | 6 | ms.author: mikejo
|
7 | 7 | manager: mijacobs
|
8 | 8 | ms.subservice: test-tools
|
9 | 9 | author: mikejo5000
|
| 10 | +#customer intent: As a developer, I want to create unit test projects in Visual Studio so I can run unit tests on project code in my solution. |
10 | 11 | ---
|
11 | 12 | # Create a unit test project
|
12 | 13 |
|
13 |
| -Unit tests often mirror the structure of the code under test. For example, a unit test project would be created for each code project in the product. The test project can be in the same solution as the production code, or it can be in a separate solution. You can have multiple unit test projects in a solution. |
| 14 | +Unit tests often mirror the structure of the code under test. For example, a unit test project might be created for each code project in the product. The test project can be in the same solution as the production code, or it can be in a separate solution. You can have multiple unit test projects in a solution. |
14 | 15 |
|
15 | 16 | > [!NOTE]
|
16 |
| -> The location of unit tests for native code and the test project structure can be different than the structure that's described in this article. For more information, see [Writing unit tests for C/C++](writing-unit-tests-for-c-cpp.md). |
| 17 | +> The location of unit tests for native code and the test project structure can be different from the structure described in this article. For more information, see [Writing unit tests for C/C++](writing-unit-tests-for-c-cpp.md). |
17 | 18 |
|
18 | 19 | ## To create a unit test project
|
19 | 20 |
|
20 | 21 | 1. On the **File** menu, select **New** > **Project**, or press **Ctrl**+**Shift**+**N**.
|
21 | 22 |
|
22 |
| -2. On the **Create a new project** page, type **unit test** into the search box. Select the project template for the test framework that you want to use, for example **MSTest Test Project** or **NUnit Test Project**, and then select **Next**. |
| 23 | +1. On the **Create a new project** page, enter *unit test* in the search box. Select the project template for the test framework that you want to use, such as **MSTest Test Project** or **NUnit Test Project**, and then select **Next**. |
23 | 24 |
|
24 | 25 | ::: moniker range=">=vs-2022"
|
25 |
| -  |
| 26 | + :::image type="content" source="media/vs-2022/test-project-templates.png" alt-text="Screenshot of test project templates in Visual Studio 2022."::: |
26 | 27 | ::: moniker-end
|
27 | 28 | ::: moniker range="vs-2019"
|
28 |
| -  |
| 29 | + :::image type="content" source="media/vs-2019/test-project-templates.png" alt-text="Screenshot of test project templates in Visual Studio 2019."::: |
29 | 30 | ::: moniker-end
|
30 | 31 |
|
31 |
| -3. On the **Configure your new project** page, enter a name for your project, and then select **Create**. |
| 32 | +1. On the **Configure your new project** page, enter a name for your project, and then select **Create**. |
32 | 33 |
|
33 |
| -4. In your unit test project, add a reference to the code under test. To add a reference to a code project in the same solution: |
| 34 | +1. In your unit test project, add a reference to the code under test. To add a reference to a code project in the same solution: |
34 | 35 |
|
35 |
| - 1. Select the test project in **Solution Explorer**. |
| 36 | + 1. In **Solution Explorer**, right-click the test project, and select **Add** > **Reference**. |
36 | 37 |
|
37 |
| - 2. On the **Project** menu, select **Add Reference**. |
| 38 | + 1. In **Reference Manager**, select the **Solution** node under **Projects**. |
| 39 | + |
| 40 | + 1. Select the code project you want to test, and then select **OK**. |
38 | 41 |
|
39 |
| - 3. In **Reference Manager**, select the **Solution** node under **Projects**. Select the code project you want to test, and then select **OK**. |
40 |
| - |
41 |
| - If the code that you want to test is in another location, see [Managing references in a project](../ide/managing-references-in-a-project.md) for information about adding a reference. |
| 42 | + If the code you want to test is in another location, see [Managing references in a project](../ide/managing-references-in-a-project.md) for information about adding a reference. |
42 | 43 |
|
43 | 44 | ## Related content
|
44 | 45 |
|
|
0 commit comments