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
What is the primary purpose of continuous integration (CI) in relation to C++ unit testing?
Answer: To automatically build and run the test suite on every code change, providing fast feedback
CI systems automatically compile and run tests on each commit, catching regressions early before they reach shared branches.
Which technique involves feeding random or malformed inputs to a C++ function to discover crashes and undefined behavior?
Answer: Fuzzing
Fuzzing (fuzz testing) generates random or mutated inputs and feeds them to the program, often combined with sanitizers to find crashes, hangs, and memory errors.
What does the `override` specifier contribute to code quality in C++ class hierarchies?
Answer: It causes a compile error if the function does not actually override a base class virtual function
The override specifier makes the compiler verify the function matches a base-class virtual signature, preventing silent bugs when signatures drift.
In Google Test parameterized tests using INSTANTIATE_TEST_SUITE_P, what is the benefit over writing separate TEST_F for each case?
Answer: The same test logic runs automatically with multiple input sets, reducing code duplication
INSTANTIATE_TEST_SUITE_P feeds multiple parameter sets into a single test body, eliminating copy-paste test functions that differ only in inputs.
What is 'cyclomatic complexity' and why is it relevant to code quality?
Answer: A count of linearly independent paths through a function, indicating testability and maintenance risk
Cyclomatic complexity counts decision points (branches, loops, cases) in a function; higher values mean more paths to test and higher defect probability.
Which of the following best describes 'dependency injection' as applied to improve C++ unit testability?
Answer: Passing dependencies (e.g., interfaces or pointers) into a class rather than constructing them internally, so tests can supply mocks
Dependency injection decouples a class from its concrete dependencies, making it straightforward to inject mock objects during testing instead of real implementations.
What is the key difference between 'white-box testing' and 'black-box testing' in C++ unit testing?
Answer: White-box testing uses knowledge of the internal implementation; black-box testing tests only the public interface
White-box (or glass-box) testing designs test cases based on internal code structure and paths, while black-box testing treats the unit as an opaque function of inputs to outputs.