← All CPP Flashcard Decks

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
  1. What distinguishes a 'mock' from a 'fake' in unit testing?

    Answer: Mocks verify interaction expectations; fakes are working lightweight implementations

    A fake has a real but simplified implementation (e.g., an in-memory database), while a mock records and verifies that specific methods were called with expected arguments.

  2. Which Google Test macro causes the entire test to immediately abort on failure, unlike its non-ASSERT counterpart?

    Answer: ASSERT_TRUE

    ASSERT_* macros abort the current test function immediately on failure, whereas EXPECT_* macros record the failure but continue executing the test.

  3. What is 'mutation testing' in the context of C++ code quality?

    Answer: Automatically introducing small code changes (mutants) to verify the test suite catches them

    Mutation testing tools (like Mull for C++) inject small faults into the code and check whether existing tests detect them, measuring test suite effectiveness.

  4. When should you use EXPECT_THROW in Google Test?

    Answer: To verify that a specific expression throws an exception of a given type

    EXPECT_THROW(expression, ExceptionType) verifies that evaluating the expression throws an exception of exactly the specified type.

  5. What is 'branch coverage' and how does it differ from 'line coverage'?

    Answer: Branch coverage ensures every conditional outcome (true/false) is tested; line coverage only checks if a line executes

    Line coverage tracks whether each line ran, but branch coverage requires that both the true and false paths of every conditional are exercised by tests.

  6. What does the ThreadSanitizer (TSan) detect in C++ multithreaded applications?

    Answer: Data races where two threads access shared memory without synchronization

    TSan instruments the binary to detect data races—concurrent unsynchronized accesses to the same memory location where at least one access is a write.

  7. In C++ static analysis, what is a 'false positive'?

    Answer: A warning reported by the tool for code that is actually correct

    A false positive is a diagnostic the static analyzer incorrectly flags as a problem when the code is actually valid and safe.