Test Driven Development (TDD) Essentials Quiz: Catching and Preventing Bugs Quiz

  1. TDD Cycle Steps

    Which of the following represents the correct sequence of steps in the TDD cycle when developing a new feature?

    1. Red, Green, Refactor
    2. Green, Red, Refactor
    3. Refactor, Red, Green
    4. Red, Refactor, Green
    5. Green, Refactor, Red
  2. TDD for Bug Fixes

    When fixing a bug in an existing codebase using TDD, what is the best first step to take?

    1. Write a failing test that exposes the bug
    2. Delete the buggy function entirely
    3. Deploy immediately to production
    4. Refactor the code before adding any tests
    5. Add a comment explaining the bug
  3. Test Specificity

    What is the benefit of writing a specific, focused test for each feature or bug in TDD?

    1. It makes it easier to pinpoint failures when bugs are introduced
    2. It increases the number of lines of code unnecessarily
    3. It hides bugs by spreading them across multiple files
    4. It ensures code runs faster by skipping tests
    5. It reduces the need for documentation
  4. Interpreting a Failing Test

    You added a new feature and run your test suite, seeing the following test failure message: 'Expected output: 5, Actual output: 7'. What should you do next according to TDD principles?

    1. Fix the implementation so the test passes
    2. Remove the test since it fails
    3. Deploy the code anyway
    4. Comment out the failing line in the test
    5. Write manual test cases instead
  5. Testing for Edge Cases

    Why is it important to include edge cases when writing tests in TDD?

    1. Edge cases can reveal bugs that normal inputs might not catch
    2. Edge cases slow down development unnecessarily
    3. It is required by all testing frameworks
    4. They always fail and should be avoided
    5. Edge cases make code less readable
  6. Refactoring Safely

    How does TDD help ensure that refactoring existing code doesn’t introduce new bugs?

    1. Existing tests confirm that code changes do not break expected behavior
    2. It skips testing altogether
    3. Refactoring is discouraged when using TDD
    4. TDD only works for new features, not refactoring
    5. It encourages merging untested code
  7. Recognizing a Good Test

    Which characteristic does NOT describe a good unit test in the context of TDD?

    1. Fragile and dependent on unrelated code
    2. Clear assertion for expected behavior
    3. Can be run automatically and quickly
    4. Tests one concept or behavior at a time
    5. Repeatable result regardless of order
  8. TDD in Legacy Code

    You’re tasked with fixing a bug in legacy code that currently has no tests. Which is the best first step using TDD?

    1. Write a test that reproduces the bug before fixing it
    2. Fix the bug and avoid tests since the code is old
    3. Rewrite the entire codebase
    4. Add comments describing the bug
    5. Ignore the bug and focus on new features
  9. Identifying Flaky Tests

    After adding new tests for a recently added feature, you notice some tests sometimes pass and sometimes fail without code changes. What is this scenario called?

    1. Flaky tests
    2. Memory leaks
    3. Optimized tests
    4. Redundant assertions
    5. Coverage overflow
  10. TDD Preventing Bugs

    How does practicing TDD help reduce the number of bugs when adding new features?

    1. By forcing you to define expected behavior before writing implementation
    2. By allowing you to skip regression testing
    3. By focusing only on manual testing
    4. By reducing the time spent on code
    5. By encouraging hardcoding values