How to get a list of mocked object with OCMock

54 views Asked by At

Is there a way to get the list of object which have been mocked.

The reason i asked is because we have a lot of test and some of them don't seem to clean up their mock properly. Those leaked mock then fail at random time later...

So if there is a list of mocked object that i can consult at the end of each test, then i could verify that all the mock have safely been destroyed and easily catch offending tests.

Thanks

1

There are 1 answers

0
Ben Flynn On BEST ANSWER

OCMock doesn't keep a central registry of mocked objects, so you'll need to do your own bookkeeping. Any time I mock a class method, I always call "stopMocking" on that mock at the end of my test, which cleans up a lot. For instance objects, recreating as many of them as you can at the start of each test is probably safest (e.g. if you have a singleton, re-initialize it after each test).