NLTQuickCheck 0.0.1

NLTQuickCheck 0.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2014年12月

KAZUMA Ukyo 维护。



  • 作者:
  • KAZUMA Ukyo

NLTQucikCheck

像 Haskell QuickCheck 一样,是 Objective-C。

功能

QuickCheck 是一个随机测试库。它生成随机值,并使用这些值运行多个测试用例。让我们开始数据驱动测试。

如何安装

CocoaPods](https://github.com/CocoaPods/)

dependency 'NLTQuickCheck'

使用方法

BDD 风格(Kiwi)

describe(@"QuickCheck", ^{
    it(@"BDD style example", ^{
        NLTQTestable *testable = [NLTQTestable testableWithPropertyBlockArguments2:^BOOL(id argA, id argB) {
            return [Math add:[argA intValue] b:[argB intValue]] == [argA intValue] + [argB intValue];
        } arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
        [testable check];
        [[theValue([testable success]) should] beYes];
        NSLog(@"%@", [testable prettyReport]);
    });
});
// Tests: 100
//   ✓ Successes  : 100
//   ✗ Failures       : 0
//   ✷ Exceptions : 0

xUnit 风格(OCUnit)

- (BOOL)propAdd:(NSNumber*)a b:(NSNumber*)b {
    return [Math add:[a intValue] b:[b intValue]] == [a intValue] + [b intValue];
}
- (void)testQuickCheckXUnitStyleExample {
    NLTQTestable *testable = [NLTQTestable testableWithPropertySelector:@selector(propAdd:b:) 
                                                                 target:self
                                                            arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
    [testable check];
    STAssertTrue([testable success], @"%@", [testable prettyReport]);
}
// Tests: 100
//   ✓ Successes  : 100
//   ✗ Failures       : 0
//   ✷ Exceptions : 0

失败(异常)情况

it(@"failure case", ^{
    NLTQTestable *testable = [NLTQTestable testableWithPropertyBlockArguments2:^BOOL(id argA, id argB) {
        return [argA intValue] - [argB intValue] > 0;
    } arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
    [testable verboseCheck];
    [[theValue([testable success]) should] beYes];
    NSLog(@"%@", [testable prettyReport]);  
});
//Tests: 100
//  ✓ Successes   : 29
//  ✗ Failures  : 71
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( 206 , 502 )
//    ....
//    ✗ Failure  : ( -8537 , 26611 )
//  ✷ Exceptions: 0

默认算子库

NSString

  • [NSString arbitary]
  • [NSString alphabetStringArbitrary]

NSNumber

  • [NSNumber intArbitrary]
  • [NSNumber nonZeroIntArbitrary]
  • [NSNumber doubleArbitrary]
  • [NSNumber boolArbitrary]