All quizzes
Free quiz · 20 questions in the bank

Mock quiz

Test your Mock knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.

Question 1/12Score 0

What is `create_autospec()` and how does it differ from `Mock(spec=SomeClass)`?

In this round
  1. What is `create_autospec()` and how does it differ from `Mock(spec=SomeClass)`?
  2. What is the basic behavior of a `Mock` object when you access an attribute or call a method on it that you haven't explicitly configured?
  3. What is `Mock.return_value` used for?
  4. What does `mock.reset_mock()` do?
  5. What is `Mock`'s `assert_not_called()` used to verify?
  6. What problem does using `spec` or `autospec` (e.g. `Mock(spec=RealClass)` or `patch(..., autospec=True)`) solve?
  7. What is `unittest.mock` (Python's "Mock" library)?
  8. What does `mock.assert_called_once_with(arg1, arg2)` verify?
  9. What is a reasonable justification for writing a test that mocks a third-party HTTP API client, rather than making a real network call to that API during the test?
  10. What is a common downside/risk of over-mocking in a test suite (mocking too many collaborators of the code under test)?
  11. What is `PropertyMock` used for?
  12. What is the purpose of using a mock as a context manager via `patch(...)` combined with the `with` statement, versus the decorator form `@patch(...)`?
Gaps to close?
Read the curated Mock notes — core concepts, patterns, interview prep.
Mock notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web