Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3398994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:43:00+00:00 2026-05-18T04:43:00+00:00

Edit: This was all caused by a typo in my Other Link Flags setting.

  • 0

Edit: This was all caused by a typo in my Other Link Flags setting. See my answer below for more information.


I’m attempting to mock a UIWebView so that I can verify that methods on it are called during a test of an iOS view controller. I’m using an OCMock static library built from SVN revision 70 (the most recent as of the time of this question), and Google Toolbox for Mac’s (GTM) unit testing framework, revision 410 from SVN. I’m getting the following error when the view controller attempts to call the expected method.

Test Case '-[FirstLookViewControllerTests testViewDidLoad]' started.
2010-11-11 07:32:02.272 Unit Test[38367:903] -[NSInvocation getArgumentAtIndexAsObject:]: unrecognized selector sent to instance 0x6869ea0
2010-11-11 07:32:02.277 Unit Test[38367:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSInvocation getArgumentAtIndexAsObject:]: unrecognized selector sent to instance 0x6869ea0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x010cebe9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x012235c2 objc_exception_throw + 47
    2   CoreFoundation                      0x010d06fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01040366 ___forwarding___ + 966
    4   CoreFoundation                      0x0103ff22 _CF_forwarding_prep_0 + 50
    5   Unit Test                           0x0000b29f -[OCMockRecorder matchesInvocation:] + 216
    6   Unit Test                           0x0000c1c1 -[OCMockObject handleInvocation:] + 111
    7   Unit Test                           0x0000c12a -[OCMockObject forwardInvocation:] + 43
    8   CoreFoundation                      0x01040404 ___forwarding___ + 1124
    9   CoreFoundation                      0x0103ff22 _CF_forwarding_prep_0 + 50
    10  Unit Test                           0x0000272a -[MyViewController viewDidLoad] + 100
    11  Unit Test                           0x0000926c -[MyViewControllerTests testViewDidLoad] + 243
    12  Unit Test                           0x0000537f -[SenTestCase invokeTest] + 163
    13  Unit Test                           0x000058a4 -[GTMTestCase invokeTest] + 146
    14  Unit Test                           0x0000501c -[SenTestCase performTest] + 37
    15  Unit Test                           0x000040c9 -[GTMIPhoneUnitTestDelegate runTests] + 1413
    16  Unit Test                           0x00003a87 -[GTMIPhoneUnitTestDelegate applicationDidFinishLaunching:] + 197
    17  UIKit                               0x00309253 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
    18  UIKit                               0x0030b55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    19  UIKit                               0x0030aef0 -[UIApplication _run] + 452
    20  UIKit                               0x0031742e UIApplicationMain + 1160
    21  Unit Test                           0x0000468c main + 104
    22  Unit Test                           0x000026bd start + 53
    23  ???                                 0x00000002 0x0 + 2
)
terminate called after throwing an instance of 'NSException'
/Users/gjritter/src/google-toolbox-for-mac-read-only/UnitTesting/RunIPhoneUnitTest.sh: line 151: 38367 Abort trap              "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents

My test code is:

- (void)testViewDidLoad {
    MyViewController *viewController = [[MyViewController alloc] init];

    id mockWebView = [OCMockObject mockForClass:[UIWebView class]];
    [[mockWebView expect] setDelegate:viewController];

    viewController.webView = mockWebView;

    [viewController viewDidLoad];
    [mockWebView verify];
    [mockWebView release];
}

My view controller code is:

- (void)viewDidLoad {
    [super viewDidLoad];
    webView.delegate = self;
}

I did find that the test would run successfully if I instead used:

- (void)testViewDidLoad {
    MyViewController *viewController = [[MyViewController alloc] init];

    id mockWebView = [OCMockObject partialMockForObject:[[UIWebView alloc] init]];
    //[[mockWebView expect] setDelegate:viewController];

    viewController.webView = mockWebView;

    [viewController viewDidLoad];
    [mockWebView verify];
    [mockWebView release];
}

However, as soon as I added the expectation that is commented out, the error returned when using the partial mock.

I have other tests that are successfully using mocks in the same project.

Any ideas? Is mocking of UIKit objects supported by OCMock?

Edit: Based on advice in the answer below, I tried the following test, but I’m getting the same error:

- (void)testViewDidLoadLoadsWebView {
    MyViewController *viewController = [[MyViewController alloc] init];
    UIWebView *webView = [[UIWebView alloc] init];

    // This test fails in the same fashion with or without the next line commented
    //viewController.view;

    id mockWebView = [OCMockObject partialMockForObject:webView];
    // When I comment out the following line, the test passes
    [[mockWebView expect] loadRequest:[OCMArg any]];

    viewController.webView = mockWebView;

    [viewController viewDidLoad];
    [mockWebView verify];
    [mockWebView release];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:43:01+00:00Added an answer on May 18, 2026 at 4:43 am

    This turned out to be one of those off by one character issues that you don’t notice until you’ve looked at it a few dozen times.

    Per this post on the OCMock forums, I had set my Other Linker Flags for my unit test target to -ObjC -forceload $(PROJECT_DIR)/Libraries/libOCMock.a. This is wrong; -forceload should have been -force_load. Once I fixed this typo, my tests worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
EDIT 1 I do not exclude at all this might be caused by something
I have this function to edit all fields that come from the form and
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
EDIT : This question duplicates How to access the current Subversion build number? (Thanks
Edit: This code is fine. I found a logic bug somewhere that doesn't exist
(EDIT: This question is now outdated for my particular issue, as Google Code supports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.