Good Code
The good version names the edge case and asserts the exact status. CI fails when validation accepts an empty title or returns the wrong error.
Lesson 10
Write C++ tests that assert edge cases directly instead of printing values for reviewers to inspect.
#include <cassert>
void rejects_empty_title()
{
// Test name and assertion capture the boundary case.
assert(validate_review("", 80) == ReviewStatus::empty_title);
}
int main()
{
rejects_empty_title();
}#include <iostream>
int main()
{
auto status = validate_review("", 80);
// Printing the status makes CI pass even when the value is wrong.
std::cout << static_cast<int>(status) << "\n";
}The good version names the edge case and asserts the exact status. CI fails when validation accepts an empty title or returns the wrong error.
The bad version prints the status and exits successfully. The test only works if a person reads the log and notices the wrong number.