Course in Unit Testing in C++ with Catch2

Course in writing C++ unit tests using Catch2

Do not write one single production code without having a associated unit-test. In this course we go straight to the point and teach you how to use Catch2 to write solid unit tests.
This is what you will learn
  • Install and configure Catch2
  • Writing efficient unit tests
  • Dealing with test-data in nested test-cases
  • Being able to formulate assertions and matchers
  • Designing BDD-style tests
  • Writing parameterized tests
Course Contents

Unit Testing and TDD

  • Type of tests
  • What is a unit test
  • Write F.I.R.S.T. tests
  • Structure of a unit test
  • Given-when-then style
  • What is test driven development (TDD)

Installation of Catch2

  • Catch2 at GitHub
  • Download the header-only library
  • Automatic download and configuration using CMake
  • Configuration of CLion to run Catch2

Writing a Test Function

  • Including Catch
  • Defining a test runner
  • Structure of a test function
  • Usage of REQUIRE()
  • Analyzing a failed test

Assertions

  • REQUIRE vs. CHECK macros
  • Dealing with floating-point comparisons
  • Asserting exceptions
  • Logging

Matchers

  • What is a matcher?
  • Using REQUIRE_THAT()
  • String matchers
  • Vector matchers
  • Floating-point matchers
  • Predicate lambda matchers
  • User-defined matchers

Test Fixtures

  • Defining a test function with nested SECTION blocks
  • Defining test data (fixture)
  • How nested test cases are executed and handed test data
  • Tagged test cases
  • Special tags

Scenarios and BDD-Style Test Cases

  • Defining a SCENARIO
  • Defining a test case using GIVEN / WHEN / THEN
  • Conjunctions

Parameterized Tests

  • Defining a TEMPLATE_TEST_CASE
  • Type-parameterized tests
  • Test-data generators
  • Value generators
  • Predicate-based generators
  • Random value generators
  • User-defined generators

Micro Benchmarks

  • What is a benchmark?
  • Enable benchmarking
  • Defining a BENCHMARK

Configuration

  • Writing your own main() function
  • Command-line options
  • Invoking the test runner
  • Compile-time configuration properties
  • Command-line options
  • Log reporters
  • CMake integration
Facts
NameUnit Testing in C++ with Catch2
Duration1 Days
LevelIntermediate
AudienceExperienced C++ programmers
PrerequisitesKnowledge about Modern C++
Tools
  • GCC/G++ compiler, version 8 or later
  • Jetbrains CLion IDE
  • Ubuntu Linux @ VirtualBox or WLS @ Windows-10
On-Site Course

If you order an On-Site course, we will come to you and hold the course in your office. The price is determined by our price model and is based on the number of course days, number of participants and any travel and lodging.

Read more about out price modell and term of sales here.

Related Courses
CourseDaysLevel
C++ 11/14/17 for C++ Programmers3IntermediateShow
Threads Programming using Modern C++3AdvancedShow
Linux Systems Programming using Modern C++3AdvancedShow
C++ Supplementary3Intermediate Show