Defining, discovering, and running tests
Testing is the staple diet for any software engineer who takes pride in quality software. The number of frameworks to write unit tests in the various languages is huge, and, especially for C++, CMake includes modules to work with most of the more popular ones.
At very abstract levels, all unit testing frameworks do the following:
- Allow the formulation and grouping of test cases
- Contain some form of assertion to check for various test conditions
- Discover and run test cases, either altogether or a selection of them
- Produce a test result in a variety of formats, such as plain text, JSON, and XML
With the CTest utility, CMake includes a built-in way to execute almost any test. Any CMake project that has set enable_testing()
and added at least one test with add_test()
has testing support enabled. Any call to enable_testing()
will enable test discovery in the current directory and any directory below it, so it is often...