Mocking
Mocking is a concept of stubbing the dependencies so as to test the piece of code in isolation. Mocking is an important concept for unit testing because most of our code would, in one way or another, depend on the external piece of code. So, if we want to test our code and just our code logic without worrying about the impact of dependencies, we need to mock those dependencies.
Mocking allows us to create a dummy object of the dependencies, and pass this dummy object to our code so as to make sure that the dependency has no impact on the execution of our code.
For example, we have to test a customer class, but the customer class also calls external dependencies such as an HTTP or database. So, to be able to test the customer class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access