Excessive Mocking

Definition:

  • Refers to a test case which requires many mocks to run [35, 45]. The system under test may need a complex environment, specific resources, or depend on 3rd party systems which cannot be provided during test execution. Running tests against a database is a canonical example. If the database isn’t available, all tests will fail even though the system under test might be completely bug-free. A common solution is to mock those potential failures by mimicking the behavior of real objects. Developers also use mocks when testing authentication, but sometimes struggle with strategy.

References:

Quality attributes

  • - Code Example

  • - Cause and Effect

  • - Frequency

  • - Refactoring