jonaszmclaren
jonaszmclaren

Reputation: 2489

OCMock Testing delegate methods

I have following protocol:

@objc protocol SomeProtocol {
    func someMethod()
}

and then some class conforming to that protocol:

class SomeClass: SomeProtocol {
    ...
    func someMethod() {
        // do something
    }
}

My question: how to test (I'm testing in Objective-C with OCMock) that e.g. method call written in someMethod() implemented by SomeClass is actually called?

Many thanks.

Upvotes: 0

Views: 2351

Answers (1)

J.C. Chaparro
J.C. Chaparro

Reputation: 1079

I'm not that knowledgeable in Swift, so I cannot give you a completely accurate answer, however, for Obj-C, I do something like this:

id mockDelegate = OCMProtocolMock(@protocol(CallViewControllerDelegate));
self.cVC.delegate = mockDelegate;
OCMExpect([mockDelegate callOutcomeSuccessful:OCMOCK_ANY]);
OCMVerifyAll(mockDelegate);

With this, you set up an expectation for a mock delegate object, on which you can later verify the call to the delegate method.

Upvotes: 2

Related Questions