OCMock on latest SDK

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.

OCMock on latest SDK

Postby creed » 18 Sep 2010, 14:43

I’ve downloaded the latest iOS SDK, Xcode 3.2.<redacted>, from Apple and can’t get OCMock to work.

Initially it was throwing up lots of symbol not found errors, but I followed this link that suggested that I rebuild the static library download from source: http://mlb5000behrend.blogspot.com/2010/09/ocmock-iphone-41-sdk.html. I've done that, and copied the resulting files into my project.

That did indeed help, stopping most of the errors that were being generated on build.

However, when it gets to the Run Script phase of the Test Target

Code: Select all
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" 1> /tmp/RunUnitTests.out


it crashes out with the following:

Code: Select all
Test Suite '/Users/andyw/Documents/XCodeBuildFolder/Debug_[Simulator]-iphonesimulator/MyApp.octest(Tests)' started at 2010-09-18 12:34:39 GMT
Test Suite 'LogicTests' started at 2010-09-18 12:34:39 GMT
Test Case '-[LogicTests testReturnsStubbedReturnValue]' started.
2010-09-18 13:34:39.188 otest[72145:903] -[NSMethodSignature methodReturnTypeWithoutQualifiers]: unrecognized selector sent to instance 0x2145fb0
2010-09-18 13:34:39.191 otest[72145:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSMethodSignature methodReturnTypeWithoutQualifiers]: unrecognized selector sent to instance 0x2145fb0'
*** Call stack at first throw:
(
   0   CoreFoundation                      0x004da4e9 __exceptionPreprocess + 185
   1   libobjc.A.dylib                     0x002ce40e objc_exception_throw + 47
   2   CoreFoundation                      0x004dbffb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
   3   CoreFoundation                      0x0044bc86 ___forwarding___ + 966
   4   CoreFoundation                      0x0044b842 _CF_forwarding_prep_0 + 50
   5   MyApp                              0x00f055b9 -[OCMReturnValueProvider handleInvocation:] + 59
   6   CoreFoundation                      0x00442839 -[NSArray makeObjectsPerformSelector:withObject:] + 265
   7   MyApp                              0x00f04c6c -[OCMockObject handleInvocation:] + 1063
   8   MyApp                              0x00f0481d -[OCMockObject forwardInvocation:] + 43
   9   CoreFoundation                      0x0044bd24 ___forwarding___ + 1124
   10  CoreFoundation                      0x0044b842 _CF_forwarding_prep_0 + 50
   11  MyApp                              0x00f014fe -[LogicTests testReturnsStubbedReturnValue] + 206
   12  CoreFoundation                      0x0044af9d __invoking___ + 29
   13  CoreFoundation                       0x0044ae71 -[NSInvocation invoke] + 145
   14  SenTestingKit                       0x2010464a -[SenTestCase invokeTest] + 69
   15  SenTestingKit                       0x20104d1f -[SenTestCase performTest:] + 192
   16  SenTestingKit                       0x2010444b -[SenTest run] + 88
   17  SenTestingKit                       0x20106fa7 -[SenTestSuite performTest:] + 115
   18  SenTestingKit                       0x2010444b -[SenTest run] + 88
   19  SenTestingKit                       0x20106fa7 -[SenTestSuite performTest:] + 115
   20  SenTestingKit                       0x2010444b -[SenTest run] + 88
   21  SenTestingKit                       0x20106871 +[SenTestProbe runTests:] + 174
   22  otest                               0x000023b3 0x0 + 9139
   23  otest                               0x000025de 0x0 + 9694
   24  otest                               0x00002086 0x0 + 8326
   25  otest                               0x00002035 0x0 + 8245
)
terminate called after throwing an instance of 'NSException'
/Developer/Tools/RunPlatformUnitTests.include: line 415: 72145 Abort trap              "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"


The test in question:

Code: Select all
- (void) testReturnsStubbedReturnValue
{
   id mock = [OCMockObject mockForClass:[NSString class]] ;
   [[[mock stub] andReturn:@"megamock"] lowercaseString] ;
   id returnValue = [mock lowercaseString] ;
   
   STAssertEqualObjects( @"megamock", returnValue, @"Should have returned stubbed value." ) ;
}


Any ideas where it’s going wrong?

Andy W
creed
 
Posts: 2
Joined: 18 Sep 2010, 14:27

Re: OCMock on latest SDK

Postby johannth » 22 Sep 2010, 13:25

I'm also having similar problems with OCMock in XCode 3.2.4 after rebuilding using the instructions from the same url. My problem, however, is:

An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSection testName]: unrecognized selector sent to instance 0x2029130a0

Any ideas?
johannth
 

Re: OCMock on latest SDK

Postby scottdensmore » 05 Oct 2010, 06:57

There is a fix posted for the xcode unit testing break here https://devforums.apple.com/thread/68687?tstart=0.
scottdensmore
 
Posts: 1
Joined: 05 Oct 2010, 06:56

Re: OCMock on latest SDK

Postby creed » 05 Oct 2010, 11:14

@scottdensmore. That does indeed fix a more general unit testing error, but doesn't fix the specific issues with OCMock unrecognised selector errors as far as I can tell. Even after applying that fix it still chokes. (And yes, I am the Andy referred to in that thread with the Stack Overflow work-around post, before the fix from Michael Jurewitz was released.)

Cheers

Andy W
creed
 
Posts: 2
Joined: 18 Sep 2010, 14:27

Re: OCMock on latest SDK

Postby erik » 28 Jan 2011, 16:11

Just in case you find this via a search engine: "Latest SDK" refers to 4.1 in this thread. Thanks to some improvements by Apple, the current versions of OCMock should adapt better to new SDK releases.
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: OCMock on latest SDK

Postby Ron Midthun » 28 Jan 2011, 21:28

To creed:
I had the exact same problems with running tests, even in the latest SDK4.2.

I fixed it by setting the following in Other Linker Flags:
-ObjC
-force_load $(PROJECT_DIR)/UnitTesting/OCMock/libOCMock.a

you will likely have to change the path to your static library.
If this isn't set categories which add methods (such as methodReturnTypeWithoutQualifiers) won't get loaded from the library.

To erik:
This is still the case on SDK 4.2 and I suspect those linker flags will always be required.
Ron Midthun
 

Re: OCMock on latest SDK

Postby erik » 29 Jan 2011, 12:45

Rod,

you're right, while Apple is improving some parts, the problems with categories in static libraries remain. In fact the problem is even worse for the LLVM compiler at the moment (as discussed in another topic here).

To help with this issue in particular, I've just added some code to the initialiser of OCMockObject that explicitly checks for the categories and raises an exception with a (hopefully) more helpful error text if they are not present. Maybe that alone is worth a new release...

Update: the latest code in Subversion (r76) should build in Xcode 4 GM.

erik
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany


Return to OCMock



cron