How to use OCMock to verify that the asynchronous method is not called in Objective-C?

I want to check that the function is called not . The function is executed in an asynchronous call of the block inside the function under test, and therefore OCMReject()does not work.

The way I tested if the async functions are actually called will be as follows:

id mock = OCMClassMock([SomeClass class]);
OCMExpect([mock methodThatShouoldExecute]);
OCMVerifyAllWithDelay(mock, 1);

How will the test be conducted to check if the forbidden function is prohibited? Sort of:

VerifyNotCalled([mock methodThatShouoldExecute]);
OCMVerifyAllWithDelay(mock, 1);
+4
source share
1 answer

OCMStrictClassMock OCMClassMock ( ). , - , , .

, , :

OCMReject([mock methodThatShouoldExecute]);

. " () " OCMock.

, , , . OCMVerifyAllWithDelay, , , , , . - 1 . XCTestExpectation. - :

XCTestExpectation *asyncTaskCompleted = [self expectationWithDescription:@"asyncTask"];
// Enqueued, in an onCompletion block, or whatever call 
//  ... [asyncTaskCompleted fulfill]

[self waitForExpectationsWithTimeout:1 handler:nil]
+1

Source: https://habr.com/ru/post/1693616/


All Articles