Mocking


Mocking is a technique used in software testing to isolate the unit being tested and replace its dependencies with mock objects. The purpose of mocking is to simulate the behavior of real objects without actually executing their code. This makes testing faster, more reliable, and more isolated from external factors that could affect the outcome of the test.

For example, if a unit of code makes a call to a database or a web service, it may be difficult or time-consuming to test this code by actually executing the database or web service code. In this case, a mock object can be used to simulate the behavior of the database or web service and return the results that the unit being tested is expecting. This makes it possible to test the unit of code in isolation, without having to worry about the behavior of the database or web service.

Mocking can be used to test a variety of scenarios, including error conditions, edge cases, and complex interactions between units. Mocking can also be used to test code that is difficult or impossible to test otherwise, such as code that makes calls to external systems or code that performs complex calculations.

META

Status:: #wiki/notes/mature
Plantations:: Software Testing - 20230221103934
References:: ILOG