???Kiwi??????????
???????????? ???????[ 2017/7/3 16:14:47 ] ??????????????? ???????
????????
????????????iOS???????????????????????????????iOS??????????????????????????Kiwi??OHHTTPStubs????????÷???????????
???????????????
????????????——??????????????????????й???
????????????——???API???????棬????????????????а???
??????????е?????????
???????????????????——???????????????????????????????
???????????
??????UIView?????????磺ViewModel????????
?????????????????Public API?????????
????????ò???????
??????????з???????з?????????????????????
????????stub??з?????????????????з??????????????????????????????stub??????????????
????????stub??????????????????????????г?????????????????????????滻????????????????????????????????????????????????????????????
???????????ViewController??View??????????????????????????????????????????xib??Storyboard???????
?????????????????????
??????п????????????
?????????——??????????????????????????????????????????????????????????????????
?????????——??????ж???ò??????????
??????????——???????????????????????????????
??????????????——????API??????????????????????????????????????????????и???
?????????
????XCTest??????
??????Xcode?????????????????????÷???????????????
????????????????????XCTestCase??????????????????test??????????????????????????
???????
??????д????д?????
??????????????????????????????????????????????????????????????ū???????????????????????
??????????????????????????????????岻????????
??????????????????????????????????????У???????????
????????mock??stub
????Kiwi??????
????iOS????????????????????BDD?????????????XCTest??????????????XCTest?????
????Kiwi???????????????????????????????????????????????????????????????????????д????????????????????????????????
????????÷???ο???https://github.com/kiwi-bdd/Kiwi/wiki
???????????
??????????????????????????????????????????????????????????????????????????Spec????????????????磺XXViewModelSpec.m?????XXViewModel???????????
????????????????:
???????Xcode Kiwi??壺??????????Xcode Templates??????install-templates.sh?????
??????·??Xcode-New-File-Kiwi Spec????
???????ò???????Cmd+U?????????е????????????????Test navigator??????????
????Kiwi?????????÷?
// XXViewModelSpec.m???????
SPEC_BEGIN(XXViewModelSpec) //????????????????
// describe??Give??????????????????????
// 1???????????????????describe
describe(@"XXViewModel"?? ^{
// context??When??????????????????????????block???????????????
// 1??describe?????????context
context(@"when created"?? ^{
__block XXViewModel *viewModel = nil;
// ??????????????????????????beforeEachblock??????
beforeEach(^{
viewModel = [[XXViewModel alloc] init];
});
// ?????????????????к???????afterEach??????
afterEach(^{
viewModel = nil;
});
// it??block??????????????
// it??Then???????????????????????????????block???????????????????
it(@"should not be nil"?? ^{
// shouldNot??beNil???kiwi???????
// ???????????????????[[testObje should] doSomething] ??[[testObje shouldNot] doSomething] ???????
// should??doSomething????????????ο???https://github.com/kiwi-bdd/Kiwi/wiki/Expectations
[[viewModel shouldNot] beNil];
});
// 1??context?????????it????????????????
it(@"should have 2 sections"?? ^{
// theValue?kiwi?????????????????????????NSNumber
[[theValue([viewModel numberOfSections]) should] equal:@(2)];
});
});
};
SPEC_END
????BDD????????
????BDD?????????????????????Given..When..Then?????
???????α????
????Give????????????????????
????When???????????????
????Then???????????????
???????磬?????????????????????????????????????
????Given a XXViewModel?? when created?? it should not be nil.
????Given a XXViewModel?? when created?? it should have 2 sections
??????????????????????????????????????????????λ????
??????
???·???
??????????????????
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