How do I properly unit-test a class or module?

This page summarizes the projects mentioned and recommended in the original post on /r/cpp_questions

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • Catch

    A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)

  • First of all, use a testing library, it makes life a lot easier. I mostly use https://github.com/catchorg/Catch2 You can pass cli args to specify which tests to run, and it makes things a whole lot simpler.

  • cmake-examples

    Useful CMake Examples

  • Some nice examples of basic CMake usage including how to set it up for unit tests: https://github.com/ttroy50/cmake-examples

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • Google Test

    GoogleTest - Google Testing and Mocking Framework

  • For unit test library, besides Catch2, another big one is Google Test. No matter which you pick, be sure to read their documentation, tutorials, examples etc. They are not hard to figure out and get started with.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts