Unexpected method invoked - <unknown> location

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Unexpected method invoked - <unknown> location

Postby jruskiew » 13 Mar 2014, 21:34

Howdy all:
If we fail to mock the method -myMethod of the class MyClass and we are testing a piece of code that uses -myMethod, we will get the message:
-[MyTestClass myTestMethod] failed
OCMockObject[MyClass]:unexpected method invoked: myMethod

for the test class MyTestClass and test method myTestMethod. The error is just fine, however Xcode 5.1 with XCTest does not know where to direct the programmer as the context of the failing call is not given to Xcode. In the issues panel, we will see the location reported as <unknown>, which for larger tests makes this very hard to see where this unexpected method is being invoked. The problem is that the exception comes from the linked binary and not from the call site.

Is this possible to get the exception to happen at the call site and not buried in OCMockObject -handleInvocation? Any work or plan on this? I am guessing (hoping?) there is some way to encode the call location. More than happy to pitch in on this.

Thanks!
jruskiew
 
Posts: 1
Joined: 13 Mar 2014, 21:11

Re: Unexpected method invoked - <unknown> location

Postby lindberg » 22 Mar 2014, 05:17

The easiest way is to put the call to real code inside of the XCTAssertNoThrow macro (or STAssertNoThrow if still using SenTestingKit). That will direct the failure to that line of code. It's a good idea to do the same around any "verify" calls to mock objects for similar reasons.

There is a pull request which managed to implement a scheme which would point at the actual expect/reject which failed using SenTestingKit, but that required changing "expect" and "reject" into a very special macro which would record the line and file of the call in the test class, which could be an issue if "expect" or "reject" was used in any other context (like a variable name).
lindberg
 
Posts: 8
Joined: 04 Oct 2013, 07:05


Return to OCMock



cron