• iOS Kiwi 测试代码例子


    #import <Kiwi/Kiwi.h>

    #import "UCService.h"

    #import "AppManager.h"

    SPEC_BEGIN(UCServiceClass)

    describe(@"UCService", ^{

         UCService *__block ucService = nil;

         AppManager *__block appManager = nil;

        beforeEach(^{

           ucService = [[UCService alloc] init];

        });

        beforeAll(^{

            appManager = [AppManager manager];

        });

          context(@"test requests", ^{

            it(@"when test request register image", ^{

                [[ucService shouldNot] beNil];

                RACSignal *signal = [ucService getRegisterImageAuthCode];

                [[signal shouldNot] beNil];

                __block ResponseModel *result = nil;

                [signal subscribeNext:^(id x) {

                    result = x;

                }];

                [[expectFutureValue(result) shouldEventually] beKindOfClass:[ResponseModel class]];

                [[expectFutureValue(result.body) shouldEventually] beNonNil];

                [[expectFutureValue(result.body.allKeys) shouldEventually] contain:@"code"];

            });

            context(@"modify password", ^{

                ResponseModel *__block responseModel = nil;

                it(@"when test modify password", ^{

                    [appManager clearUserInfo:^(BOOL completed) {

                    }];

                    UCService* __weak weakUCService = ucService;

                    RACSignal *signal = [[ucService loginWithTel:@"17317969263" password:@"999999"] flattenMap:^RACStream *(id value) {

                        UCService* __strong strongUCService = weakUCService;

                        return [strongUCService modifyPassowrdWithOldPassowrd:@"999999"newPwd:@"999999"confirmNewPwd:@"999999"];

                    }];

                    [[signal shouldNot] beNil];

                    [signal subscribeNext:^(id x) {

                        responseModel = x;

                    }];

                    [[expectFutureValue(responseModel.body) shouldEventually] beKindOfClass:[NSDictionary class]];

                    [[expectFutureValue(responseModel.body) shouldEventually] beNonNil];

                    [[expectFutureValue(responseModel.head.responseCode) shouldEventually] equal:@"0000"];

                });

                context(@"sub context1", ^{

                    //内嵌上下文/描述会在外围上下文执行完后才执行

                    it(@"when received result", ^{

                        [[responseModel.head.responseMsg shouldNot] beNil];

                    });

                });

            });

            context(@"login context with right account info", ^{

                // 测试正确账号的情况

                ResponseModel *__block loginResponse = nil;

                it(@"login with telephone with ", ^{

                    [appManager clearUserInfo:^(BOOL completed) { }];

                    RACSignal *signal = [ucService loginWithTel:@"17317969263" password:@"999999"];

                    [signal subscribeNext:^(id x) {

                        loginResponse = x;

                    }];

                    [[expectFutureValue(loginResponse) shouldEventually] beKindOfClass:[ResponseModel class]];

                    [[expectFutureValue(loginResponse.head) shouldEventually] beNonNil];

                    [[expectFutureValue(loginResponse.head.responseCode) should] equal:@"000000"];

                });

                context(@"anylize response", ^{

                    // 如果response还有多个子控制状态可以在nested context中做处理

                });

            });

            context(@"login context with wrong account info", ^{

                // 测试错误账号的情况

                Error *__block loginError = nil;

                it(@"login with telephone with ", ^{

                    [appManager clearUserInfo:^(BOOL completed) {

                    }];

                    RACSignal *signal = [ucService loginWithTel:@"17317969263" password:@"123456"];

                    [signal subscribeError:^(NSError *error) {

                        loginError = (Error *)error;

                    }];

                    [[expectFutureValue(loginError) shouldEventually] beKindOfClass:[Error class]];

                    [[expectFutureValue(loginError.errMsg) shouldNot] beNil];

                    [[expectFutureValue(loginError.errCode) shouldNot] beNil];

                    [[expectFutureValue(loginError.errMsg) shouldNot] beEmpty];

                    [[expectFutureValue(loginError.errCode) shouldNot] beEmpty];

                    [[expectFutureValue(loginError.errCode) shouldNot] equal:@"0000"];

                });

            });

        });

       });

    SPEC_END

     

  • 相关阅读:
    关于import和from xx import xx
    Python中import机制
    定制化的IPython配置
    ajax请求封装函数
    ajax-----readyState总结
    console控制台的小问题
    http协议基本知识
    cookie猜数字游戏(下)------------以及cookie使用的不安全之处
    cookie猜数字游戏(上)---------------思路分析(踩坑)
    Cookie隐藏小广告
  • 原文地址:https://www.cnblogs.com/codetime/p/6605252.html
Copyright © 2020-2023  润新知