A mock object is a form of Test Stub where it is based on interfaces, is easier to setup and control, isolates code from details that may be filled in later, and can be refined incrementally by replacing with actual code.

Based on Dependency Inversion where test control mocks test behaviour.

You can create these manually, or with popular frameworks.

Characteristics

  • A mock object is a dummy implementation for an interface or a class where you define the output of method calls (hard coded).

  • Steps

    • Configure (mock or spy)
    • Define output (stub)
    • Verify interaction
  • Mockito