Always use the most specific test assertion method available for your test case rather than generic assertions. Specific assertions provide better error messages and make test failures easier to debug.
Always use the most specific test assertion method available for your test case rather than generic assertions. Specific assertions provide better error messages and make test failures easier to debug.
For string comparisons, use EXPECT_STREQ
instead of ASSERT_TRUE
with string equality:
// Instead of:
ASSERT_TRUE(json == testValue);
// Use:
EXPECT_STREQ(json.c_str(), testValue.c_str());
For exception testing, use EXPECT_THROW
to properly verify exceptions instead of manually catching them:
// Instead of:
try {
lru.evict();
// Test will pass even if no exception is thrown
} catch (...) {
// ...
}
// Use:
EXPECT_THROW(lru.evict(), SomeExceptionType);
Specific assertions like these will print the actual and expected values when tests fail, making debugging much faster and providing clearer failure messages in test reports.
Enter the URL of a public GitHub repository