Unit Testing & Code Quality Flashcards
7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Unit Testing & Code Quality flashcards as text
In Google Test, which macro should you use to verify that two floating-point values are approximately equal within a default tolerance?
Answer: EXPECT_FLOAT_EQ
EXPECT_FLOAT_EQ checks that two float values are within 4 ULPs of each other, which is the standard way to compare floats in GTest.
What is a 'test fixture' in the context of C++ unit testing frameworks like Google Test?
Answer: A class that provides shared setup and teardown logic for a group of tests
A test fixture is a class (often inheriting from ::testing::Test) that encapsulates shared state and setup/teardown methods reused across multiple related test cases.
Which clang-tidy check category specifically targets potential C++ modernization opportunities such as replacing loops with range-based for?
Answer: modernize-*
The modernize-* checks in clang-tidy suggest transformations that move code toward modern C++ idioms like range-based for, nullptr, and override.
In test-driven development (TDD), what is the correct order of the 'Red-Green-Refactor' cycle?
Answer: Write failing test → make it pass → refactor
TDD's Red-Green-Refactor cycle starts with a failing test (Red), then writes minimal code to pass it (Green), then cleans up the code (Refactor).
What does the AddressSanitizer (ASan) tool primarily detect in C++ programs?
Answer: Memory safety errors such as buffer overflows and use-after-free
AddressSanitizer instruments the binary at compile time to detect memory errors including heap/stack buffer overflows, use-after-free, and use-after-return.
Which of the following is the best practice when naming unit test functions in Google Test using TEST_F?
Answer: TestSuiteName_TestName (underscore-separated descriptive names)
Google Test uses TEST_F(TestSuiteName, TestName) where both parts are PascalCase or descriptive identifiers separated by an underscore at the macro level.
What is 'code coverage' as measured by tools like gcov or llvm-cov?
Answer: The percentage of source lines or branches executed during test runs
Code coverage measures what fraction of executable lines, branches, or functions are actually exercised when the test suite runs.