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/writing-unit-tests-for-c-cpp.md
+31-9Lines changed: 31 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
2
title: "Write unit tests for C/C++ in Visual Studio"
3
-
ms.date: 11/04/2017
3
+
ms.date: 10/09/2018
4
4
ms.prod: visual-studio-dev15
5
5
ms.technology: vs-ide-test
6
6
ms.topic: conceptual
7
7
ms.author: "mblome"
8
-
manager: douge
9
-
ms.workload:
8
+
manager: wpickett
9
+
ms.workload:
10
10
- "cplusplus"
11
11
author: mikeblome
12
12
---
@@ -26,6 +26,10 @@ Visual Studio includes these C++ test frameworks with no additional downloads re
26
26
27
27
In addition to the installed frameworks, you can write your own test adapter for whatever framework you would like to use within Visual Studio. A test adapter can integrate unit tests with the **Test Explorer** window. Several third-party adapters are available on the [Visual Studio Marketplace](https://marketplace.visualstudio.com). For more information, see [Install third-party unit test frameworks](install-third-party-unit-test-frameworks.md).
28
28
29
+
**Visual Studio 2017 version 15.7 (Professional and Enterprise)**
30
+
31
+
C++ unit test projects support [CodeLens](../ide/find-code-changes-and-other-history-with-codelens.md).
32
+
29
33
**Visual Studio 2017 version 15.5**
30
34
31
35
-**Google Test Adapter** is included as a default component of the **Desktop development with C++** workload. It has a project template that you can add to a solution via the **Add New Project** context menu on the solution node in **Solution Explorer**, and options you can configure via **Tools** > **Options**. For more information, see [How to: use Google Test in Visual Studio](how-to-use-google-test-for-cpp.md).
@@ -74,13 +78,14 @@ TEST_CLASS and TEST_METHOD are part of the [Microsoft Native Test Framework](mic
74
78
A TEST_METHOD returns void. To produce a test result, use the static methods in the `Assert` class to test actual results against what is expected. In the following example, assume `MyClass` has a constructor that takes a `std::string`. We can test that the constructor initializes the class as expected like so:
75
79
76
80
```cpp
77
-
TEST_METHOD(TestClassInit)
78
-
{
79
-
std::string name = "Bill";
80
-
MyClass mc(name);
81
-
Assert::AreEqual(name, mc.GetName());
82
-
}
81
+
TEST_METHOD(TestClassInit)
82
+
{
83
+
std::string name = "Bill";
84
+
MyClass mc(name);
85
+
Assert::AreEqual(name, mc.GetName());
86
+
}
83
87
```
88
+
84
89
In the previous example, the result of the `Assert::AreEqual` call determines whether the test passes or fails. The Assert class contains many other methods for comparing expected vs. actual results.
85
90
86
91
You can add *traits* to test methods to specify test owners, priority and other information. You can then use these values to sort and group tests in **Test Explorer**. For more information, see [Run unit tests with Test Explorer](run-unit-tests-with-test-explorer.md).
@@ -106,6 +111,23 @@ For more information about using **Test Explorer**, see [Run unit tests with Tes
106
111
107
112
For best practices related to unit testing, see [Unit test basics](unit-test-basics.md)
108
113
114
+
## Use CodeLens
115
+
116
+
**Visual Studio 2017 version 15.7 Professional and Enterprise Editions only**:
117
+
[CodeLens](../ide/find-code-changes-and-other-history-with-codelens.md) enables you to quickly see the status of a unit test without leaving the code editor. You can initialize CodeLens for a C++ unit test project in any of these ways:
118
+
119
+
- Edit and build your test project or solution.
120
+
- Rebuild your project or solution.
121
+
- Run test(s) from the **Test Explorer** window.
122
+
123
+
After **CodeLens** is initialized, you can see test status icons above each unit test.
0 commit comments