??????????????API??OCMock??汾??API???°汾???????汾??API?????????????汾??API???????????????°汾??OCMock3????API??????ο???
??????????
??????????????????????????Xcode5???????XCTest??????BBD???????Kiwi????????iOS??????
????????mock????????????
??????????д?????????????????????????????????????Щ?????????????????????????????????????????????????????У????????????????м??????????????????mock???????????????????class??mock????????е????α???????????????????????????????????????????????е?????????????????????????б?????????????????????mock??????????????
??????????mock??e???
????stub????
??????????????????????????????OCMock??????stub????
????id jalopy = [OCMock mockForClass[Car class]];
????[[[jalopy stub] andReturn:@"75kph"] goFaster:[OCMArg any] units:@"kph"];
????// if returning a scalar value?? andReturnValue: can be used
????OCMock3 ?°汾???API
????id jalopy = OCMStrictClassMock([Car class]);
????OCMStub([jalopy goFaster:[OCMArg any] units:@"kph"]).andReturn(@"75kph");
????// if returning a scalar value?? andReturnValue: can be used
????????????????????Car????mock?????jalopy(?????)?????stub??goFaster:?????????????????@”75kph”??stub????????????е?????????????????????
????ourMockObject stub] whatItShouldReturn ] method:
????OCMock3 ?°汾???API
????OCMStub([ourMockObject method:]).andReturn()
???????????????????????[OCMArg any]???÷??????????????????????????????????ò???????????????????mock????andReturn:????????[OCMArg any]????????stub??????е???????????????
????[car goFaster:84 units:@"mph"];
??????????stub???????????????????”kph”.
????????
????OCMock????mock????????????????????????????????????????????????????????????£???????????????????????classMethod???????????
????[[[[jalopy stub] classMethod] andReturn:@"expired"] checkWarrany];
??????OCMock3??classMethod??instanceMethod??stub???????????磺
????id classMock = OCMClassMock([SomeClass class]);
????OCMStub([classMock aClassMethod]).andReturn(@"Test string");
????// result is @"Test string"
????NSString *result = [SomeClass aClassMethod];
????mock???? – niceMock??partialMock
????OCMock??????????????mock????????????????????ó?????
??????????????????????mock??
????id mockThing = [OCMock mockForClass[Thing class]];
????OCMock3 ?°汾???API
????id mockThing = OCMStrictClassMock([Thing class]);
???????????????‘vanilla’ mock??‘vanilla’ mock????????????stub???????????????????????????????????mock??????mock????????????????????????????stub???(?????????????????stub)
???????????stub?????????‘nice’ mock??‘nice’ mock???????ò???????????????stub???????????????????????
????id niceMockThing = [OCMock niceMockForClass[Thing class]];
????OCMock3 ?°汾???API
????id mockThing = OCMClassMock([Thing class]);
?????????mock??????‘partial’ mock??????????stub?????????????????????????????????????????????mock????????????????????????????Щ???????????????stub??
????Thing *someThing = [Thing alloc] init];
????id aMock = [OCMockObject partialMockForObject:someThing]
????OCMock3 ?°汾???API
????Thing *someThing = [Thing alloc] init];
????id aMock = OCMPartialMock(someThing);
??????????????????
?????????????????÷???????????????expect????????????????:
????id niceMockThing = [OCMock niceMockForClass[Thing class]];
????[[niceMockThing expect] greeting:@"hello"];
????// verify the method was called as expected
????[niceMocking verify];
????OCMock3 ?°汾???API
????id niceMockThing = OCMClassMock([Thing class]);
????OCMVerify([niceMockThing greeting:@"hello"]);
??????????????????б???????????????????????????XCTest?????????XCTAss**NotThrow???????????á???????????????????????????????????????????????????stub??selector?????????????????????????????????????????[OCMArg any]???????????????