what is mock? Link to heading
as it implies, it is a object that pretend it being something else.
why we want to mock? Link to heading
Assume that we want to test a function. Let’s call it count_all_after_connection(connection). It consumed a parameter called connection, and this connection is not available so far(possibly because of not having access yet).
But you still want to test it, but how?
The solution is that you mock a connction for this function so that you don’t have to connect with the actual source.
After you mock one connection, you send this fake connection to the real function, and see what happened.
Remember, it should behave as if it has a real connection.
when to use mock? Link to heading
For example, when the resource is not easy to connect. Situation includes connecting to a database, an activity requiring long time processing time, etc.