C++ Unit Testing Frameworks (GoogleTest)
🟡 Intermediate
📖 Definition
Unit testing frameworks like GoogleTest (gtest) or Catch2 automate verifying function return values and class behavior using assertions (EXPECT_EQ, ASSERT_TRUE, EXPECT_THROW).
💡 Code Example
#include <iostream>
#include <cassert>
int add(int a, int b) { return a + b; }
void runTests() {
assert(add(2, 2) == 4);
assert(add(-1, 1) == 0);
std::cout << "All Unit Tests Passed Successfully!\n";
}
int main() {
runTests();
return 0;
}