????????
????????????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
??????????????????????????????????????????????λ????