OCMock通过键值观察给出了错误

时间:2018-09-19 18:20:39

标签: objective-c key-value-observing ocmock

-(void)testPause_trial
{
    MyMediaPlayer *player = [[MyMediaPlayer alloc]init];

    id mock = [OCMockObject partialMockForObject:player];

    AVQueuePlayer* result = [[AVQueuePlayer alloc]init];
    result.actionAtItemEnd = AVPlayerActionAtItemEndPause;

    [result addObserver:player forKeyPath:@"status" options:0 context:nil];

    [result addObserver:player forKeyPath:@"rate" options:0 context:nil];

    [(PTMediaPlayer*)[[mock stub] andReturn:result] createAVQueuePlayer:OCMOCK_ANY];

    //Start playing
    [player play];

    [player pause];

    [mock stopMocking];

}

没有这一行“ [[(PTMediaPlayer *)[[mock stub] andReturn:result] createAVQueuePlayer:OCMOCK_ANY];”,我的代码可以正常工作。

但是要包括这一行:

  1. 未为keypath = @“ status”调用observeValueForKeyPath
  2. 对于keypath = @“ rate”,出现以下错误:

    observeValueForKeyPath:ofObject:change:context:消息已收到但未处理。

    关键路径:费率

    观察对象:

    更改:{     kind = 1; }

    上下文:0x0“ (     0 CoreFoundation 0x000000010bcce1e6 例外预处理+ 294     1个libobjc.A.dylib 0x000000010b363031 objc_exception_throw + 48     2 CoreFoundation 0x000000010bd43975 + [NSException提高:格式:] + 197     3基础0x000000010ace15ca-[NSObject(NSKeyValueObserving)watchValueForKeyPath:ofObject:change:context:] + 161     4 Tests_new 0x0000000125f05110-[PTMediaPlayer watchValueForKeyPath:ofObject:change:context:] + 176     5 CoreFoundation 0x000000010bc51ccc __invoking _ + 140     6 CoreFoundation 0x000000010bc51b84-[NSInvocation调用] + 308     7 CoreFoundation 0x000000010bc505f8 转发 + 760     8 CoreFoundation 0x000000010bc50278 _CF_forwarding_prep_0 + 120     9基础0x000000010ac01820 NSKeyValueNotifyObserver + 349     10基础0x000000010ac010d7 NSKeyValueDidChange + 483     11基础0x000000010ace1422 NSKeyValueDidChangeWithPerThreadPendingNotifications + 148     12 AVFoundation 0x000000011b6e04f3-[AVPlayer didChangeValueForKey:] + 47     13 AVFoundation 0x000000011b6e724f-[AVPlayer setRate:withVolumeRampDuration:playImmediatelyly:rateChangeReason:] + 797     14 AVFoundation 0x000000011b6e730f-[AVPlayer setRate:] + 84     15 Tests_new 0x0000000125f3ac6a-[PTTimelineManager暂停] + 250     16 Tests_new 0x0000000125f01706-[PTMediaPlayer暂停] + 182     17 CoreFoundation 0x000000010bc51ccc 调用_ + 140     18 CoreFoundation 0x000000010bc51b84-[NSInvocation调用] + 308     19 CoreFoundation 0x000000010bc505f8 转发 + 760     20 CoreFoundation 0x000000010bc50278 _CF_forwarding_prep_0 + 120     21 Tests_new 0x0000000125de49d7-[PTMediaPlayerTests testPause_trial] + 2183     22 CoreFoundation 0x000000010bc51ccc 调用_ + 140     23 CoreFoundation 0x000000010bc51b84-[NSInvocation调用] + 308     24 XCTest 0x000000010b20a01a __24- [XC​​TestCase invokeTest] _block_invoke.184 + 74     25 XCTest 0x000000010b264ae3 + [XCTestCase(Failures)performFailableBlock:shouldInterruptTest:] + 36     26 XCTest 0x000000010b264a2e-[XCTestCase(Failures)_performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 54     27 XCTest 0x000000010b209ce3 __24- [XC​​TestCase invokeTest] _block_invoke + 847     28 XCTest 0x000000010b269a7d-[XCUITestContext performInScope:] + 248     29 XCTest 0x000000010b20997f-[XCTestCase invokeTest] + 175     30 XCTest 0x000000010b20b555 __26- [XC​​TestCase performTest:] _ block_invoke_2 + 42     31 XCTest 0x000000010b264ae3 + [XCTestCase(Failures)performFailableBlock:shouldInterruptTest:] + 36     32 XCTest 0x000000010b264a2e-[XCTestCase(Failures)_performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 54     33 XCTest 0x000000010b20b402 __26- [XC​​TestCase performTest:] _ block_invoke.318 + 90     34 XCTest 0x000000010b271061 + [XCTContext runInContextForTestCase:block:] + 225     35 XCTest 0x000000010b20aaff-[XCTestCase performTest:] + 673     36 XCTest 0x000000010b24d727-[XCTest runTest] + 57     37 XCTest 0x000000010b206341 __27- [XC​​TestSuite performTest:] _ block_invoke + 365     38 XCTest 0x000000010b205b1d-[XCTestSuite _performProtectedSectionForTest:testSection:] + 55     39 XCTest 0x000000010b205dde-[XCTestSuite performTest:] + 296     40 XCTest 0x000000010b24d727-[XCTest runTest] + 57     41 XCTest 0x000000010b206341 __27- [XC​​TestSuite performTest:] _ block_invoke + 365     42 XCTest 0x000000010b205b1d-[XCTestSuite _performProtectedSectionForTest:testSection:] + 55     43 XCTest 0x000000010b205dde-[XCTestSuite performTest:] + 296     44 XCTest 0x000000010b24d727-[XCTest runTest] + 57     45 XCTest 0x000000010b206341 __27- [XC​​TestSuite performTest:] _ block_invoke + 365     46 XCTest 0x000000010b205b1d-[XCTestSuite _performProtectedSectionForTest:testSection:] + 55     47 XCTest 0x000000010b205dde-[XCTestSuite performTest:] + 296     48 XCTest 0x000000010b24d727-[XCTest runTest] + 57     49 XCTest 0x000000010b27afa6 __44- [XC​​TTestRunSession runTestsAndReturnError:] _ block_invoke + 40     50 XCTest 0x000000010b21e389-[XCTestObservationCenter _observeTestExecutionForBlock:] + 594     51 XCTest 0x000000010b27adb1-[XCTTestRunSession runTestsAndReturnError:] + 369     52 XCTest 0x000000010b1ecc71-[XCTestDriver runTestsAndReturnError:] + 447     53 XCTest 0x000000010b26fbb1 _XCTestMain + 960     54 xctest 0x000000010a8a72a4主+ 571     55 libdyld.dylib 0x000000011289b955开始+ 1 )

    任何帮助都会很棒!

0 个答案:

没有答案