Introduction to Mocking

Get familiar with the concept of mocking in the context of unit testing.

In automated testing, mocking refers to creating fake or simulated objects and behaviors to isolate and test a software application’s specific components or functionalities. Mocking is commonly used in unit testing to ensure that individual units of code—including functions, methods, and classes—behave as expected, even if they rely on external dependencies, such as databases, APIs, or services.

For example, we may have a dependency in a class we test that normally calls an external service via the network. This cannot be executed in unit testing because we don’t ...