Software Engineering Week 2
A mock is an object that is used when unit testing to simulate a dependency used in an application. A mock is useful in unit testing because it allows you to isolate a single method or class and simulate responses by mocking specific return values of a dependency to test for expected responses. In our Java applications this is done with the Mockito library. In addition, mocks allow for fast test execution. By mocking out a database connection for example, you ignore the latency induced by having to connect to a real database and interact with real data. By using a mock in this case, you can simulate a database connection, a database connection error, and test how a method responds when a database query returns specific values.
Comments
Post a Comment