Test rig exited abnormally with code 134 with OCMock verify on iOS 4

前端 未结 4 717
梦如初夏
梦如初夏 2021-01-03 08:52

I\'m trying to add OCMock to my iOS 4 project. To test it out, I have a class Person with one method, -hello. When I run this test:



        
相关标签:
4条回答
  • 2021-01-03 08:57

    I have found that this bug is still around with Xcode 4/SDK 4.3 in April of 2011. For example, Test A passes, Test B crashes the test rig.

    Test A:

    - (void)testAcceptsAndVerifiesExpectedMethods
    {
    
        id mock = [OCMockObject mockForClass:[NSString class]];
    
        [[mock expect] lowercaseString];
        [mock lowercaseString];
    
        [mock verify];
    }
    

    Test B:

    - (void)testAcceptsAndVerifiesExpectedMethods
    {
    
        id mock = [OCMockObject mockForClass:[NSString class]];
    
        [[mock expect] lowercaseString];
        //[mock lowercaseString];
    
        [mock verify];
    }
    
    0 讨论(0)
  • 2021-01-03 09:06

    I'd say it's a bug. Verify should report a useable result, even if it fails.

    0 讨论(0)
  • 2021-01-03 09:10

    You don't have a bad configuration, it's a bug that Apple introduced in the simulator SDK when they released iOS4. Basically, if code invoked using an NSInvocation object throws an exception, then that exception is uncatchable. I wrote about the issue when it first appeared here:

    http://pivotallabs.com/users/adam/blog/articles/1302-objective-c-exceptions-thrown-inside-methods-invoked-via-nsinvocation-are-uncatchable

    Unfortunately, this bug affects OCMock and Apple hasn't show much interest in fixing it. Many people have filed bug reports, but to no avail.

    I realize this is little comfort, but you will get slightly better error messages when using Cedar for testing (I believe the same is true for GTM).

    0 讨论(0)
  • 2021-01-03 09:14

    A workaround I've found is to wrap the [mockObject expect] and [mockObject verify] calls with XCTAssertNoThrow, e.g.:

    XCTAssertNoThrow([[mockTaskVC expect] showAlertWithTitle:containsString(@"Error") message:OCMOCK_ANY completion:OCMOCK_ANY], @"threw up exception");
    

    This will catch the exception and fail the text rather than crashing.

    Credit to author here: http://www.mulle-kybernetik.com/forum/viewtopic.php?f=4&t=315&p=710&hilit=unexpected+method+was+not+invoked+exception#p710

    0 讨论(0)
提交回复
热议问题