How to testing an C++ exercise correctly

Hello! I’m trying to add a new test for a C++ exercise locally, but I do not understand why when I use the command “make” it doesn’t run all the tests. I think is something related to the cmakelists. In the test file I found this line before all the tests

#if defined(EXERCISM_RUN_ALL_TESTS)

Do I need to use a flag or something when I run the make command? Thank you!

When you use Exercism’s client (the “CLI”) to download the exercise it will also download a file HELP.md that explains the role of this macro.

In short: This construct allows you to focus at one test at a time when you’re solving the exercise locally, similar to Test Driven Development (TDD).
Initially only the first test is enabled, the other tests are disabled by the #if defined(EXERCISM_RUN_ALL_TESTS) line. The intended use is that you just do enough coding that the current test succeeds, refactor the code to keep it clean, and then proceed to the next test by moving the #if defined(EXERCISM_RUN_ALL_TESTS) line one test further.
In a real TDD setting you would write the tests yourself. One test at a time, first making sure that it fails, doing just enough coding that it succeeds, refactoring it to remove inefficiencies, duplications, etc, and then moving on to the next task/test. That whole process is often called the “Red-Green-Refactor cycle”.

Alternatively, if you want to enable all tests right from the beginning and deal with all failing tests at once you can pass the command line option -DEXERCISM_RUN_ALL_TESTS=1 to cmake.

1 Like

Thank you so much!