iosxcodexctestocmock

OCMock/OCMVerify - Expression result unused


Calls like the following don't compile because of Expression result unused warning/error:

id object = [Foo new];
id mockObject = OCMPartialMock(object);
...
OCMExpect([mockObject doTheThing]);
...
OCMVerify(mockObject);

Tested on Xcode 12 GM:

$ clang -v
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_12_GM.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Solution

  • Replace OCMVerify(...) with OCMVerifyAll(...).

    OCMVerify(...) is to verify after calls after running while OCMVerifyAll(...) is to verify expectations declared before running.

    id object = [Foo new];
    id mockObject = OCMPartialMock(object);
    ...
    OCMExpect([mockObject doTheThing]);
    ...
    OCMVerifyAll(mockObject);