Search code examples
c++unit-testingcmakegoogletest

Why do I not need a call to `add_test` in cmake?


I've seen add_test a few times in cmake and I'm confused because I'm using googletest and I haven't needed a single call to add_test. Could somebody please explain why? Is this handled directly by googletest or is this call just not used when you use googletest?


Solution

  • The command adds a target (or custom command) to CTest. So whenenver you execute ctest inside the build directory, all added tests get executed. If you don't want to use CTest and simply execute your test binary manually, then there is no need to use add_test.

    In larger projects, where tests usually consist of several binaries, it is more convenient to execute all tests using using a single command (especially when your build pipeline is automated).