C++ build, testing and quality tools: CMake and beyond
You set up projects with modern CMake, write tests with GoogleTest and Catch2, and check quality automatically with sanitizers, clang-tidy and continuous integration.
Level 301 · 18 lessons · 18 practice labs
Lessons
The build system
- CMake targets and modern CMake
- Dependencies: find_package and FetchContent
- Configure presets and build types
- Package managers: vcpkg and Conan
- Short task: a project with library, app and test targets
Testing
- Unit tests with GoogleTest
- Fixtures and parameterised tests
- Mock objects with gMock
- Readable tests with Catch2
- Coverage reports: gcov and llvm-cov
- Short task: write a test suite for an existing class
Quality tools
- The sanitizer matrix: ASan, UBSan, TSan, MSan
- clang-tidy and clang-format
- gdb for C++: STL pretty printers and stopping on throw
- Inspecting compiler output: -S and objdump
- Continuous integration: build, test, analyse
- Short task: a change that passes the quality gate
Capstone
- Capstone: a tested, analysed and packaged library
Practice labs
- Separating library and application targets: Split a single-target CMake project into a library and an application using it, giving include paths with target_include_directories.
- Writing presets for build types: Write CMake presets for debug, release and sanitizer builds and show that each is configured with a single command.
- Fixing leaking compile flags: Fix a project whose flags set through global variables leak into every target using PUBLIC, PRIVATE and INTERFACE, and show the dependent target builds cleanly.
- Linking a dependency with find_package: Replace hand-written library paths with find_package and imported targets and give a clear error when the package is missing.
- Pinning a FetchContent dependency: Pin a FetchContent declaration that follows a branch name to a specific commit and hash and show it configures offline from the local mirror.
- Making a library an installable package: Add install and export rules to a library and show a separate project finds and links it through find_package together with its version file.
- Writing a first GoogleTest suite: Write GoogleTest tests for a function that turns a title into a URL slug, covering empty input, spaces and Turkish letters.
- Testing a tariff with a fixture and parameters: Test Demirsu Enerji's tiered tariff calculation with a shared fixture and a value table and expose the hidden bug at boundary consumptions.
- Mocking a payment gateway with gMock: Mock the external payment gateway a order service depends on through an interface and verify retry count and call order with expectations.
- Finding uncovered branches and adding tests: Find error branches that never run in the gcov report and add tests that raise branch coverage above ninety per cent.
- Writing readable tests with Catch2 sections: Write Catch2 tests for a date parser with SECTION blocks sharing a common setup and sweep boundary values with a generator.
- Closing the errors a sanitizer matrix finds: Write a script that runs the same test suite under ASan, UBSan and TSan separately, repair what each finds and show all three runs come out clean.
- Bringing format and lint findings to zero: Add a clang-format settings file to the project, format the code and resolve the findings of the selected clang-tidy checks.
- Finding where an exception originates with gdb: Find where an exception swallowed higher up is first thrown using catch throw and pretty printers, inspect the container and fix the bug.
- Inspecting compiler output and building a quality gate: Verify with -S and objdump whether a hot function is inlined and tie build, test, format and analysis steps to a gate in one script.
- Reading a crash backtrace with debug symbols: Rebuild a crashing program with debug symbols, run it in gdb and find the crashing line and the variable values at that moment from the backtrace.
- Writing a first Catch2 test: Write three test cases for a rounding function with Catch2 and show the difference between REQUIRE and CHECK on a failing example.
- Building a test table with generators and matchers: Turn parser tests into a data table with GENERATE, check error messages with matchers and verify the thrown exception type, leaving no duplicated test code.
About this course
You set up projects with modern CMake, write tests with GoogleTest and Catch2, and check quality automatically with sanitizers, clang-tidy and continuous integration.
What you will learn
- The build system
- Testing
- Quality tools
- Capstone
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.