Skip to content

Test double ‐ Mock

Devrath edited this page Oct 24, 2023 · 1 revision

github-header-image

Observations

  • Mocks are used to replace the interface

What mocks are used for

  • It is used to check if the function is called or not.
  • It is used to check if the right parameters are passed or not.
  • It is also used to check how many times the function is called.

What it is not used for

  • To check the return type of the function it is calling.

Example Scenario of usage

  • We call a server using retrofit
  • We actually call an abstract function of an interface and the abstract function communicates to a real server and returns data.
  • Using mocks we can make the abstract function communicate to the mock server and return data.