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

4

3

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:

- (void) testMock {
    id mock = [OCMockObject mockForClass:[Person class]];
    [[mock expect] hello];

    [mock hello];

    [mock verify];
}

Everything is fine, and the build succeeds. If I take away the hello call, like this:

- (void) testMock {
    id mock = [OCMockObject mockForClass:[Person class]];
    [[mock expect] hello];

    [mock verify];
}

I'd expect to get an error message telling me that my expected method wasn't called on the mock. Instead I get a cryptic message about the test rig crashing:

/Developer/Tools/RunPlatformUnitTests.include:451:0 Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/Developer/usr/bin/otest' exited abnormally with code 134 (it may have crashed).

Is this crash normal when an expected method isn't called? Do I have a bad configuration?

Woll answered 3/8, 2010 at 21:10 Comment(1)
I had this same error when i was testing a NSManagedObject in iOS. I solved it by writing some to make a different setup for my Managed Object Contect and Model. It solved my problem. So in my case it was a bad 'configuration' of my Managed Object Context. But i was able to solve it.Allistir
O
4

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).

Oboe answered 13/11, 2010 at 21:34 Comment(0)
C
2

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

Coquetry answered 1/9, 2010 at 19:46 Comment(1)
My workaround has been to create my own mock objects. It's tedious, but I haven't gotten OCMock to work reliably.Woll
R
2

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];
}
Reproachless answered 7/4, 2011 at 2:44 Comment(0)
B
0

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

Beefwitted answered 29/4, 2014 at 6:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.