Can I use OCMock to check if a superclass is called?

I created a subclass of MKMapView. In unit test, I want to know when I call a specific method of this subclass that the corresponding MKMapView method and the argument class are called. Can I use OCMock for this?

EDIT:

I accepted the answer, but I want to clarify that my question was discussed when the superclass cannot be directly standing in the unit test (obviously this is because inheritance works). And it looks like OCMock and OCMockito can only be used for objects that are injected into the class under the test . Therefore, basically, I think I need to resort to manual improvisations.

+4
source share
2 answers

To answer this question, let me take a little time to see how OCMock and similar frameworks work:

Mocking frameworks use Objective-C runtime for a proxy server or wrap the source class, so any method call to this class is redirected to a mocking structure that has a pre-written set of instructions on what to do when this method is called.

Therefore, the answer is yes, when you mock a class, you also implicitly make fun of superclass methods. You can record the expectation that this method will be called, and make sure that this happens. You can also check the arguments that have been set.

, , , , :

, OCMockito

+4

, OCMock .

. (iosunittesting.com)

. , , ( ), - , ( №1 ).

+2

All Articles