Using mock objects to eliminate dependencies

In order to test Deck, we have the following two choices for handling the dependencies in the Card class hierarchy:

  • Mocking: We can create a mock (or stand-in) class for the Card class and a mock card() factory function that produces instances of the mock class. The advantage of using mock objects is that we create real confidence that the unit under test is free from workarounds in one class, which make up for bugs in another class. A rare potential disadvantage is that we may have to debug the behavior of a super-complex mock class to be sure it's a valid stand-in for a real class. A complex mock object suggests the real object is too complex and needs to be refactored.
  • Integrating: If we have ...

Get Mastering Object-Oriented Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.