Member-only story

Starting Unit Testing in C++ guide

Guriy Samarin
3 min readMay 5, 2019

--

What if you have the Visual Studio C++ project and you want to add some unit tests to it? Visual Studio (starting from 2017) includes C++ unit test frameworks with no additional downloads. But I ran into some problems trying to make use of these frameworks. So I decided to write a “how to start Unit Test C++ guide” in case someone faces the same problems

So what do we need to start testing C++?

  1. Visual Studio 2017 or newer (Enterprise if you need code coverage analysis)
VS components list

2. Check if installed C++/CLI support for (for Managed Test support)

3. Add a special lib project alongside your project. You can put the code you are going to test into it

4. Add a Unit Test project into the solution. I used the Managed Test project (for Native Unit Test see part two). If you do not have Managed Test Project template (it was removed in the latest versions of VS) — create CLR Class Library for C++ and add Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll to the references (it’s in extensions)

--

--

Guriy Samarin
Guriy Samarin

Written by Guriy Samarin

Software developer at Amazon. Web (mostly backend) development now. My stack — .NET (APS.NET Core MVC).

No responses yet