Programming foundations

Stage 6 · Lesson 5 of 7

Tests with GoogleTest

Build and ship your first projects

is the most common C++ test framework. Each test is written with a macro, such as TEST(LedgerTest, TotalsOneMonth) { ... }. Assertions come in two kinds.

EXPECT_EQ records a failure and carries on, while ASSERT_EQ stops the test straight away. Use EXPECT_DOUBLE_EQ or EXPECT_NEAR for , and EXPECT_THROW(parse("abc"), std::invalid_argument) for rejected input. Pull GoogleTest into your build with .

Link your test executable against your core library and GTest::gtest_main, call enable_testing() and gtest_discover_tests, and run everything with ctest. Test the core logic rather than the file reading, and cover such as empty input and a single line.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?