首页 > 其他 > 详细

XCTest的小技巧

时间:2015-07-01 18:27:11      阅读:268      评论:0      收藏:0      [点我收藏+]

XCTest 的小技巧

试了一下在一个测试里,以不同的状态把其它测试方法跑一遍。

    // alternate what setup done

    // full tests in alternated state
    NSArray * tests = [FileLibraryTests testInvocations];
    for (NSInvocation * inv in tests ) {
        NSString * sel = NSStringFromSelector(inv.selector);
        if (![sel containsString:@"WithInit"] && ![sel containsString:@"Monitoring"]) {
            [inv invokeWithTarget:self];
        }
    }

    //back to normal state

另外,Xcode 6 已经加上了 XCTestExpetation,以后用不着:

    #import <XCTest/XCTestCase+AsynchronousTesting.h>

    dispatch_semaphore_t sema = dispatch_semaphore_create(0);

    dispatch_after(dispatch_time(0, (int64_t)(0.2 * NSEC_PER_SEC)), 
        dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 
        ^{
            ... dispatch_semaphore_signal(sema); ...
        }
    );

    dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30*NSEC_PER_SEC));

直接写

    XCTestExpectation *expectation = [self expectationWithDescription:@"xxx"];

    // invoke it in code async executing
    ... ^(){
        [expectation fulfill];
    } ...

    [self waitForExpectationsWithTimeout:1 handler:^(NSError *error) {
        // cleanup.
    }];

版权声明:本文为博主原创文章,未经博主允许不得转载。

XCTest的小技巧

原文:http://blog.csdn.net/pinxue/article/details/46711063

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!