Skip to content

Commit cc8547e

Browse files
authored
Merge pull request #7818 from corob-msft/docs/corob/6390
Address 6390 for test procedure
2 parents 51e4426 + b54a456 commit cc8547e

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

docs/test/how-to-use-microsoft-test-framework-for-cpp.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Use the Microsoft Unit Testing Framework for C++
33
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
55
ms.topic: how-to
66
ms.author: corob
77
manager: markl
@@ -27,7 +27,7 @@ In some cases, for example when testing non-exported functions in a DLL, you mig
2727

2828
1. In the Property Pages dialog, select **Configuration Properties** > **VC++ Directories**.
2929

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:
3131

3232
| Directory | Property |
3333
|-| - |
@@ -36,21 +36,23 @@ In some cases, for example when testing non-exported functions in a DLL, you mig
3636

3737
1. Add a C++ Unit Test file:
3838

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**.
4042

4143
## <a name="object_files"></a> To link the tests to the object or library files
4244

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.
4446

4547
1. In Solution Explorer, on the shortcut menu of the test project, choose **Properties**. The project properties window opens.
4648

4749
1. Select the **Configuration Properties** > **Linker** > **Input** page, then select **Additional Dependencies**.
4850

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.
5052

5153
1. Select the **Configuration Properties** > **Linker** > **General** page, then select **Additional Library Directories**.
5254

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.
5456

5557
1. Select the **Configuration Properties** > **VC++ Directories** page, then select **Include Directories**.
5658

@@ -102,7 +104,7 @@ TEST_METHOD(Method1)
102104

103105
### C++ trait attribute macros
104106

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).
106108

107109
|Macro|Description|
108110
|-|-----------------|

docs/test/how-to-write-unit-tests-for-cpp-dlls.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Write Unit tests for C++ DLLs
33
description: Learn about the several ways to test DLL code, depending on whether the DLL exports the functions that you want to test.
44
ms.custom: SEO-VS-2020
5-
ms.date: 05/01/2019
5+
ms.date: 02/16/2021
66
ms.topic: how-to
77
ms.author: corob
88
manager: markl
@@ -24,14 +24,14 @@ Add a separate test project. Link it to the output object file.
2424

2525
Go to the procedure [To link the tests to the object or library files](#objectRef).
2626

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.
2929

3030
This approach has the benefit of allowing your tests to use non-exported members, but still keep the tests in a separate project.
3131

3232
Go to the procedure [To change the DLL to a static library](#staticLink).
3333

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):**
3535
Add unit tests in the same project as the product code.
3636

3737
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).
4040

4141
### <a name="staticLink"></a> To change the DLL to a static library
4242

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.
4444

4545
1. In **Solution Explorer**, on the shortcut menu of the project under test, choose **Properties**. The project **Properties** window opens.
4646

@@ -84,7 +84,7 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
8484

8585
### <a name="objectRef"></a> To link the tests to the object or library files
8686

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.
8888

8989
1. Create a Native Unit Test Project.
9090

@@ -100,17 +100,17 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
100100

101101
::: moniker-end
102102

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**.
104104

105-
3. Choose **Configuration Properties** > **Linker** > **Input** > **Additional Dependencies**.
105+
1. Choose **Configuration Properties** > **Linker** > **Input** > **Additional Dependencies**.
106106

107-
Choose **Edit**, and add the names of the **.obj** or **.lib** files. Do not use the full path names.
107+
Choose **Edit**, and add the names of the **.obj** or **.lib** files. Don't use the full path names.
108108

109-
4. Choose **Configuration Properties** > **Linker** > **General** > **Additional Library Directories**.
109+
1. Choose **Configuration Properties** > **Linker** > **General** > **Additional Library Directories**.
110110

111111
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.
112112

113-
5. Choose **Configuration Properties** > **VC++ Directories** > **Include Directories**.
113+
1. Choose **Configuration Properties** > **VC++ Directories** > **Include Directories**.
114114

115115
Choose **Edit**, and then add the header directory of the project under test.
116116

@@ -122,26 +122,28 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
122122

123123
1. In **Solution Explorer**, in the shortcut menu of the project under test, choose **Properties**. The project **Properties** window opens.
124124

125-
2. Choose **Configuration Properties** > **VC++ Directories**.
125+
1. Choose **Configuration Properties** > **VC++ Directories**.
126126

127-
3. Edit the Include and Library directories:
127+
1. Edit the Include and Library directories:
128128

129129
|Directory|Property|
130130
|-|-|
131-
|**Include Directories** | **$(VCInstallDir)UnitTest\include;$(IncludePath)**|
132-
|**Library Directories** | **$(VCInstallDir)UnitTest\lib;$(LibraryPath)**|
131+
|**Include Directories** | **$(VCInstallDir)Auxiliary\VS\UnitTest\include** |
132+
|**Library Directories** | **$(VCInstallDir)Auxiliary\VS\UnitTest\lib** |
133133

134-
2. Add a C++ Unit Test file:
134+
1. Add a C++ Unit Test file:
135135

136-
- 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**.
137139

138140
Go to [Write the unit tests](#addTests).
139141

140142
## <a name="addTests"></a> Write the unit tests
141143

142144
1. In each unit test code file, add an `#include` statement for the headers of the project under test.
143145

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:
145147

146148
```cpp
147149
#include "stdafx.h"
@@ -165,9 +167,9 @@ Go to the procedure [To add unit tests in the same project](#sameProject).
165167

166168
1. On the **Test** menu, choose **Windows** > **Test Explorer**.
167169

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**.
169171

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.
171173

172174
## See also
173175

0 commit comments

Comments
 (0)