Manoj
Manoj

Reputation: 1003

Mock Objects for Unit Testing in iPhone app

I just downloaded OCMock lib to use Mock Objects for unit testing in one of my apps. But before all, I wanted know to how to use them and what are the benefits of using mock objects?

Upvotes: 0

Views: 1078

Answers (1)

Suhail Patel
Suhail Patel

Reputation: 13694

For the benefit of Mock Objects, I think Wikipedia has a fantastic explanation (not only limited to Objective-C or OCMock):

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A computer programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.

In a unit test, mock objects can simulate the behavior of complex, real (non-mock) objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test.

For usage examples, the OCMock website has some good tutorials listed under the Tutorial Tab on setting up Mock Objects for different uses and interacting with them. I really liked this tutorial titled Poking Objective-C with a Test Stick which explains how to get OCMock imported into your project and getting started. It was written for Xcode 3 but shouldn't be difficult to interpret for Xcode 4.

Upvotes: 2

Related Questions