zoukankan      html  css  js  c++  java
  • 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

     

  • 相关阅读:
    JDBC的一些代码
    mysql
    【转载】如何简单地理解Python中的if __name__ == '__main__'
    【转载】用Scikit-Learn构建K-近邻算法,分类MNIST数据集
    数据科学入门---可视化数据
    Sum It Up
    Blue Jeans
    Zball in Tina Town
    Island Transport
    CD
  • 原文地址:https://www.cnblogs.com/codetime/p/6605252.html
Copyright © 2011-2022 走看看