Stage 6 · Lesson 5 of 7
Tests with GoogleTest
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 repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch