Test Doubles and Testing at a Boundary · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.
به انگلیسی

Stand-ins for awkward neighbours

Computing · Software Engineering · ages 20-21
Name ______________________   Date ____________
  1. A clock double returns 10 whenever its hour method is called. Which role does that chosen response serve?

    • A mock checking hour requests
    • A stub supplying a fixed result
    • A clock reading wall time
  2. A test substitutes a controlled object for its database dependency. What is the substituted object?

    • A test double under test control
    • Another live database replica
    • An index on the real database
  3. A mock can support checking which calls a dependency received.

    Circle one:   True   False

  4. The contract requires requesting user 73 from a database dependency. Which check directly tests that required interaction?

    • Check that the returned row belongs to user 73
    • Return a canned row containing user 73 and compare the final display
    • Record the boundary request and check its user argument
  5. Greeting logic reads the current hour. Which seam lets the test choose that hour while still testing the greeting logic?

    • Replace greeting logic with a fixed result
    • Pass a clock dependency that the test can replace
    • Intercept the formatted message after greeting runs
  6. A test asserts that a private helper named load_row was called. The helper is renamed and public behaviour stays the same. Why can this assertion fail?

    • The expected row changes with the helper's name
    • The private helper name is part of the public contract
    • The assertion depends on the helper's internal name
  7. Ana substitutes a mock configured to return a chosen network response. She checks the final user message, not recorded calls. What role does the double serve here?

    • It verifies recorded requests by checking the final message
    • It supplies a controlled response in the stub role
    • It checks the network's own response instead of a substitute
  8. Application code receives a database dependency, and tests supply a compatible double. What does this design establish?

    • The test can substitute the dependency at that seam
    • The double checks compatibility with the real database
    • The injected object tests query performance
LightMySky · lightmysky.comW1-mt_4ep3SiMYNM-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Stand-ins for awkward neighbours W1-mt_4ep3SiMYNM-s1

  1. A stub supplying a fixed result · Supplying a chosen result is the stub role. The question does not state that calls are checked.
  2. A test double under test control · The controlled substitute is a test double. The seam is where the test substitutes it.
  3. True · Interaction checking is the mock role. The same object may also supply chosen responses.
  4. Record the boundary request and check its user argument · The required request must be observed. A double used for this interaction check serves the mock role.
  5. Pass a clock dependency that the test can replace · Replacing the clock dependency controls the input hour without replacing the greeting logic itself.
  6. The assertion depends on the helper's internal name · This particular assertion names an implementation detail that the refactoring changes.
  7. It supplies a controlled response in the stub role · The configured replacement supplies a controlled response. Interaction assertions are not required to use that response.
  8. The test can substitute the dependency at that seam · Receiving the dependency exposes a substitution point. It does not establish compatibility with the real database or that every test will keep passing after future internal refactorings.
Worksheet · LightMySky