Mock Objects

Facebook Twitter


EasyMock. Jmock objects. Mocks Aren't Stubs. The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing.

Mocks Aren't Stubs

Most language environments now have frameworks that make it easy to create mock objects. What's often not realized, however, is that mock objects are but one form of special case test object, one that enables a different style of testing. Using Mock Objects in Java. Mockito - simpler & better mocking. 06-10-2012: Mockito 1.9.5 released!

mockito - simpler & better mocking

See the release notes. Should appear in maven central shortly. Unit testing with mock objects. Unit testing has become widely accepted as a "best practice" for software development.

Unit testing with mock objects

When you write an object, you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate. When you're dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.