Skip to content

Test double ‐ Spy

Devrath edited this page Oct 24, 2023 · 1 revision

github-header-image (1)

Observation

  • Spy is like a partial mock meaning, a part of the object will be mocked but part of it will be real implementation.

Comparing mockk with spy

  • Mock is actually trying to be an interface.
    • When you specify a mock you are just checking the return method of that mock.
    • Mock sees just the method calls and not the structure inside it.
    • Thus mock runs the method and ignores the body.
  • Spy is trying to be the actual class.
    • By using a spy, the entire class is running, the body of the class is running, the entire structure is running.
    • Spy sees not just the calls of method but also the body in it.
    • Thus spy runs the method and the body.

Clone this wiki locally