Unit testing using mocks

With unit testing, as a rule, it is always necessary to test each object without relying on other application's objects which need testing as well. However, in many situations, the object being tested is tightly coupled with other objects. For example, the object being tested uses other objects to do its job. In such cases, mock objects help us to test the object conveniently without relying on other application's objects. Mock objects are also used in situations where testing an object needs to create other objects, such as connecting to a database, starting an application server, providing a socket object, and so on, that are costly. Mock objects work similarly to real objects, but we are sure about their operations ...

Get Spring Persistence with Hibernate now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.