Using CTest to Standardize Testing in CMake

Ultimately, automated testing involves nothing other than running an executable that sets our system under test (SUT) in a given state, performs tested operations, and checks if the results match expectations. We can think of them as a codified way of filling in the blanks in the sentence "GIVEN _ WHEN _ THEN _" and checking if it's true for SUT. As you can imagine, there's more than one way of doing this—actually, there are lots. Everything depends on the kind of framework we're going to use, how we are hooking it up to our SUT, and what is the exact configuration. Even things as minuscule as the filename of our testing binary will impact the experience of the person using our software. As there are no agreed-upon standards for these things, one developer will use the name test_my_app, another will go with unit_tests, and a third will use something obscure or not provide tests at all. Discovering which file needs to be run, which framework is used, which arguments should be passed to the runner, and how to collect results are problems that users would like to avoid.

Get hands-on with 1400+ tech skills courses.