???Kiwi??????????
???????????? ???????[ 2017/7/3 16:14:47 ] ??????????????? ???????
????????????÷???
????Stub??
????????????滻??stub?????????????????????÷????????κ?????漲??????
???????????????鷳????????????ò?????á????????????????????????????stub??????????÷???????????????????????????
context(@"when select count of termStudyInfo"?? ^{
beforeEach(^{
// stub????κε??????[EduTermStudyInfo countOfTermStudyInfoWithLearnerId:]??????????3??
// ????????[EduTermStudyInfo countOfTermStudyInfoWithLearnerId:]????????????????
[EduTermStudyInfo stub:@selector(countOfTermStudyInfoWithLearnerId:) andReturn:theValue(3)];
});
it(@"the count should always be 3"?? ^{
[[theValue([EduTermStudyInfo countOfTermStudyInfoWithLearnerId:110]) should] equal:theValue(3)];
});
});
????????????????it?????β??stub????????
Mock??
??????μ??????????????????????????mock??????????????????????mock?????????????????????????????
// ????nullMock??????????????XXSectionDataSource?????????XXSectionDataSource????κ???????????????????
XXSectionDataSource *mockLiveSection = [XXSectionDataSource nullMock];
// ?????[mockLiveSection viewType]???????XXViewTypeLive???????stub??mock?????viewType????
[mockLiveSection stub:@selector(viewType) andReturn:theValue(XXViewTypeLive)];
// ????????nullMock?????????mock??????????mock?????????mock?????????stub????????????crash
XXCellDataSource *mockCell = [XXCellDataSource nullMock];
[mockCell stub:@selector(viewType) andReturn:theValue(XXViewTypeLive)];
[mockLiveSection stub:@selector(cellDataSources) andReturn:@[mockCell?? mockCell]];
???????
??????????????????????в???????ж?????????????????????????expectFutureValue+shouldEventually ?滻????????should??
expectFutureValue+shouldEventually?????????block??????1s??????????????????????????????????????????????????
????????ο???https://github.com/kiwi-bdd/Kiwi/issues/532
describe(@"XXViewModel"?? ^{
context(@"when request lern data"?? ^{
__block XXViewModel *viewModel = nil;
__block BOOL isExecuteSuccess = NO;
beforeEach(^{
viewModel = [[XXViewModel alloc] init];
[viewModel requestLearnData:^{
isExecuteSuccess = YES;
} failure:nil target:self];
});
it(@"should eventually call successBlock"?? ^{
//???????????ж??????????????
[[expectFutureValue(theValue(isExecuteSuccess)) shouldEventually] beYes];
});
}????
OHHTTPStubs???
????NSURLProtocol???????????stub????stub?????????????????????????????????????????Charles??local map?????
???????????????????????????????????????????????????????????????????????y???????API??????С?
?÷????????beforeEach?????????stub??
// ????url?а???learn/v1????????????????learn_v1.json????е?????
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
return [request.URL.absoluteString containsString:@"learn/v1"];
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
NSString *filePath = OHPathForFile(@"learn_v1.json"?? self.class);
NSData *data = [NSData dataWithContentsOfFile:filePath];
return [OHHTTPStubsResponse responseWithData:data statusCode:kK12TestHTTPSuccessCode headers:nil];
// ??????????????????NSError
//return [OHHTTPStubsResponse responseWithError:[NSError errorWithDomain:@"kK12TestSystemErrorDomain" code:-1 userInfo:nil]];
}];
????????
????????Kiwi??EXC_BAD_ACCESS??????????Kiwi?master?°汾??https://github.com/kiwi-bdd/Kiwi/pull/649
????????????????????????????????pch??????????
??RACBacktrace??RACBacktraceBlock??debug?????EXC_BAD_ACCESS???????????ReactiveCocoa?汾??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11