简体   繁体   English

iOS Kiwi参数化测试,例如NUnit

[英]iOS Kiwi parameterized test like NUnit

Is there a way to parameterize test with Kiwi ? 有没有一种方法可以用Kiwi参数化测试?

If you are familiar with NUnit, it has a feature of running a test with parameters ( see http://www.nunit.org/index.php?p=testCase&r=2.5 ). 如果您熟悉NUnit,它具有使用参数运行测试的功能(请参阅http://www.nunit.org/index.php?p=testCase&r=2.5 )。

I ended up creating a macro that generates the if(..., ^{ }); 我最终创建了一个生成if(...,^ {})的宏;
This will show the correct error message if the test failed, but you can not debug :( . 如果测试失败,这将显示正确的错误消息,但是您无法调试:(。

Here is an example of how it looks like: 这是一个看起来像的例子:

let(_userModel, ^id{
    return [[MyUserModel alloc] init];
});

#define email_should_be_valid(email) \
    it(@ #email " should be valid", ^{\
        [_userModel setEmail:email];\
        [[theValue([_userModel validate:nil]) should] beTrue];\
    });

email_should_be_valid(@"example@dd.m")
email_should_be_valid(@"example.example@dd.x")
email_should_be_valid(@"example@dd.com")

#undef email_should_be_valid

I will not mark this answer as correct, hope somebody comes with a better solution for this. 我不会将此答案标记为正确,希望有人为此提供更好的解决方案。

There's one way that works for me. 有一种对我有用的方法。

Basically, 基本上,

  1. Define your own block in test file that gets your parameter(s) 在测试文件中定义自己的块以获取参数

     typedef void(^TestCount)(INT count); 
  2. Create the block with corresponding tests 创建具有相应测试的模块

     TestCount testCount = ^(INT count){ [[someObject shouldNot] beNil]; [[someObject should] have:count] rows]; }; 
  3. Execute parametrized block wherever you need it, i usually do this within it's block 在任何需要的地方执行参数化块,我通常在其块内执行此操作

     context(@"when adding object", ^{ beforeAll(^{ [someObject addObject:anotherObject]; }); it(@"it should have 1 object", ^{ testCount(1); }); }); 

I hope this helps 我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM