Writing Expressive Tests with Google Test and Google Mock

Опубликовано: 17 Апрель 2024
на канале: Utah Cpp Programmers
912
15

There are several unit testing frameworks for C++ out there. One of the most popular is Google Test (also known as "GTest") for writing tests and its companion library Google Mock (aka "GMock") for creating and interacting with mock objects.

Writing a test seems simple enough, until you get into the details. There are some specific challenges to writing tests that are presented by typical legacy C++ code. Even greenfield code can present you with challenges when writing tests that can make your tests less readable and cluttered. Cluttered test code makes for tests that are difficult to understand.

This month, Richard Thomson will discuss how we can get "Good Unit Tests (GUTs)" using Google Test and Google Mock, using example code from some open source projects that include both legacy code and greenfield code. Some of the topics to be discussed are:

How do I isolate some code so I can test it?
How do I decouple some code from dependencies I can't control?
How do I eliminate noise from my tests to enhance readability?
How do I use gmock argument matchers?
How do I write custom matchers?
How do I write expressive matchers for deep structures?

Google Test/Mock docs: https://google.github.io/googletest/

Source code used in this talk:
Iterated Dynamics: https://github.com/LegalizeAdulthood/...
Threaded Read News (trn): https://github.com/LegalizeAdulthood/trn
OptiX Toolkit: https://github.com/NVIDIA/optix-toolkit

Meetup: https://www.meetup.com/utah-cpp-progr...
Past topics: https://utahcpp.wordpress.com/past-me...
Future topics: https://utahcpp.wordpress.com/future-...