You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/test/how-to-use-microsoft-test-framework-for-cpp.md
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Use the Microsoft Unit Testing Framework for C++
3
3
description: Use the Microsoft Unit Testing Framework for C++ to create unit tests for your C++ code.
4
-
ms.date: 01/08/2020
4
+
ms.date: 02/16/2021
5
5
ms.topic: how-to
6
6
ms.author: corob
7
7
manager: markl
@@ -27,7 +27,7 @@ In some cases, for example when testing non-exported functions in a DLL, you mig
27
27
28
28
1. In the Property Pages dialog, select **Configuration Properties** > **VC++ Directories**.
29
29
30
-
1.Click on the down arrow in the following rows and choose **\<Edit>**. Add these paths:
30
+
1.Select the down arrow in the following rows and choose **\<Edit>**. Add these paths:
31
31
32
32
| Directory | Property |
33
33
|-| - |
@@ -36,21 +36,23 @@ In some cases, for example when testing non-exported functions in a DLL, you mig
36
36
37
37
1. Add a C++ Unit Test file:
38
38
39
-
- Right-click on the project node in **Solution Explorer** and choose **Add** > **New Item** > **C++ File (.cpp)**.
39
+
1. Right-click on the project node in **Solution Explorer** and choose **Add** > **New Item**.
40
+
41
+
1. In the **Add New Item** dialog, select **C++ File (.cpp)**, give it an appropriate name, and then choose **Add**.
40
42
41
43
## <aname="object_files"></a> To link the tests to the object or library files
42
44
43
-
If the code under test doesn't export the functions that you want to test, you can add the output **.obj** or **.lib** file to the dependencies of the test project. Modify the test project's properties to include the headers and library or object files that are required for unit testing.
45
+
If the code under test doesn't export the functions that you want to test, you can add the output *.obj* or *.lib* file to the dependencies of the test project. Modify the test project's properties to include the headers and library or object files that are required for unit testing.
44
46
45
47
1. In Solution Explorer, on the shortcut menu of the test project, choose **Properties**. The project properties window opens.
46
48
47
49
1. Select the **Configuration Properties** > **Linker** > **Input** page, then select **Additional Dependencies**.
48
50
49
-
Choose **Edit**, and add the names of the **.obj** or **.lib** files. Don't use the full path names.
51
+
Choose **Edit**, and add the names of the *.obj* or *.lib* files. Don't use the full path names.
50
52
51
53
1. Select the **Configuration Properties** > **Linker** > **General** page, then select **Additional Library Directories**.
52
54
53
-
Choose **Edit**, and add the directory path of the **.obj** or **.lib** files. The path is typically within the build folder of the project under test.
55
+
Choose **Edit**, and add the directory path of the *.obj* or *.lib* files. The path is typically within the build folder of the project under test.
54
56
55
57
1. Select the **Configuration Properties** > **VC++ Directories** page, then select **Include Directories**.
56
58
@@ -102,7 +104,7 @@ TEST_METHOD(Method1)
102
104
103
105
### C++ trait attribute macros
104
106
105
-
The following pre-defined traits are found in `CppUnitTest.h`. For more information, see [The Microsoft Unit Testing Framework for C++ API reference](microsoft-visualstudio-testtools-cppunittestframework-api-reference.md).
107
+
The following pre-defined traits are found in *`CppUnitTest.h`*. For more information, see [The Microsoft Unit Testing Framework for C++ API reference](microsoft-visualstudio-testtools-cppunittestframework-api-reference.md).
Copy file name to clipboardExpand all lines: docs/test/how-to-write-unit-tests-for-cpp-dlls.md
+22-20Lines changed: 22 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Write Unit tests for C++ DLLs
3
3
description: Learn about the several ways to test DLL code, depending on whether the DLL exports the functions that you want to test.
4
4
ms.custom: SEO-VS-2020
5
-
ms.date: 05/01/2019
5
+
ms.date: 02/16/2021
6
6
ms.topic: how-to
7
7
ms.author: corob
8
8
manager: markl
@@ -24,14 +24,14 @@ Add a separate test project. Link it to the output object file.
24
24
25
25
Go to the procedure [To link the tests to the object or library files](#objectRef).
26
26
27
-
**The unit tests call non-member functions which are not exported from the DLL, and the DLL can be built as a static library:**
28
-
Change the DLL project so that it is compiled to a *.lib* file. Add a separate test project that references the project under test.
27
+
**The unit tests call non-member functions that aren't exported from the DLL, and the DLL can be built as a static library:**
28
+
Change the DLL project so that it's compiled to a *.lib* file. Add a separate test project that references the project under test.
29
29
30
30
This approach has the benefit of allowing your tests to use non-exported members, but still keep the tests in a separate project.
31
31
32
32
Go to the procedure [To change the DLL to a static library](#staticLink).
33
33
34
-
**The unit tests must call non-member functions that are not exported, and the code must be built as a dynamic link library (DLL):**
34
+
**The unit tests must call non-member functions that aren't exported, and the code must be built as a dynamic link library (DLL):**
35
35
Add unit tests in the same project as the product code.
36
36
37
37
Go to the procedure [To add unit tests in the same project](#sameProject).
@@ -40,7 +40,7 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
40
40
41
41
### <aname="staticLink"></a> To change the DLL to a static library
42
42
43
-
- If your tests must use members that are not exported by the DLL project, and the project under test is built as a dynamic library, consider converting it to a static library.
43
+
- If your tests must use members that aren't exported by the DLL project, and the project under test is built as a dynamic library, consider converting it to a static library.
44
44
45
45
1. In **Solution Explorer**, on the shortcut menu of the project under test, choose **Properties**. The project **Properties** window opens.
46
46
@@ -84,7 +84,7 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
84
84
85
85
### <aname="objectRef"></a> To link the tests to the object or library files
86
86
87
-
- If the DLL does not export the functions that you want to test, you can add the output *.obj* or *.lib* file to the dependencies of the test project.
87
+
- If the DLL doesn't export the functions that you want to test, you can add the output *.obj* or *.lib* file to the dependencies of the test project.
88
88
89
89
1. Create a Native Unit Test Project.
90
90
@@ -100,17 +100,17 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
100
100
101
101
::: moniker-end
102
102
103
-
2. In **Solution Explorer**, on the shortcut menu of the test project, choose **Properties**.
103
+
1. In **Solution Explorer**, on the shortcut menu of the test project, choose **Properties**.
Choose **Edit**, and add the directory path of the **.obj** or **.lib** files. The path is typically within the build folder of the project under test.
- In **Solution Explorer**, in the shortcut menu of the project, choose **Add** > **New Item** > **C++ Unit Test**.
136
+
1. Right-click on the project node in **Solution Explorer** and choose **Add** > **New Item**.
137
+
138
+
1. In the **Add New Item** dialog, select **C++ File (.cpp)**, give it an appropriate name, and then choose **Add**.
137
139
138
140
Go to [Write the unit tests](#addTests).
139
141
140
142
## <aname="addTests"></a> Write the unit tests
141
143
142
144
1. In each unit test code file, add an `#include` statement for the headers of the project under test.
143
145
144
-
2. Add test classes and methods to the unit test code files. For example:
146
+
1. Add test classes and methods to the unit test code files. For example:
145
147
146
148
```cpp
147
149
#include"stdafx.h"
@@ -165,9 +167,9 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
165
167
166
168
1. On the **Test** menu, choose **Windows** > **Test Explorer**.
167
169
168
-
1. If all your tests are not visible in the window, build the test project by right-clicking its node in **Solution Explorer** and choosing**Build** or **Rebuild**.
170
+
1. If not all of your tests are visible in the window, build the test project: right-click its node in **Solution Explorer** and choose**Build** or **Rebuild**.
169
171
170
-
1. In **Test Explorer**, choose **Run All**, or select the specific tests you want to run. Right-click on a test for other options, including running it in debug mode with breakpoints enabled.
172
+
1. In **Test Explorer**, choose **Run All**, or select the specific tests you want to run. Right-click on a test for other options, for example, to run it in debug mode with breakpoints enabled.
0 commit comments