Skip to content

What are mocks

Devrath edited this page Jun 26, 2021 · 2 revisions

Defining the Mocks

  • Mocks are used to replace an interface

Scenario of use

  • Suppose we are using a retrofit service to call a web server. What we do is we call an abstract method of an interface and that calls a real server.
  • Now using mocks -> we mock a retrofit client -> then we call mock of retrofit to return the result of the mock

What mocks are not used for

  • Mocks are not used for checking the function behaviour and return values of the function.

What mocks are used for

  • Mocks are used to check if a function is called or not
  • Mocks are used to check how many times a function is called
  • Check if the right parameters are passed or not

Summarizing

Mocks are used to check the right function is called with correct parameters and executed an exact number of times

Clone this wiki locally