Unit-Testing Frameworks: GTest

Let's learn about adopting a unit-testing framework called GTest.

We'll cover the following

GTest

There are a few important advantages when it comes to using GTest: it's been around quite a long time and is highly recognized in the C++ community (thus, multiple IDEs support it natively). The company behind the biggest search engine on the planet is maintaining and using it extensively, so it's quite unlikely it will become stale or abandoned any time soon. It can test C++11 and up, so if we're stuck in a bit older environment, we're in luck.

The GTest repository comprises two projects: GTest (the main testing framework) and GMock (a library adding the mocking functionality). That means we can download both with a single FetchContent() call.

Using GTest

To use GTest, our project needs to follow the directions from the "Structuring Our Projects for Testing" lesson. This is how we'd write a unit test in this framework:

Get hands-on with 1400+ tech skills courses.