XCTestCase-RunAsync

[iOS] write async testcase by Mocha's done style.

MIT License

Stars
6
Committers
2

XCTestCase-RunAsync

This library is wrapper for ishkawa/NSRunLoop-PerformBlock.

You can write async testcase by Mocha's done style.

Usage

@interface ExampleTests : XCTestCase
@end

@implementation ExampleTests

- (void)testExample{
    [self runAsyncWithBlock:^(AsyncDone done) {
      // async function
        double delayInSeconds = 2.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_after(popTime, queue, ^(void){
            done();// => done async test
        });
    }];
}
@end

API

typedef void(^AsyncDone)();

@interface XCTestCase (RunAsync)
- (void)runAsyncWithBlock:(void (^)(AsyncDone done)) runTestCode;

- (void)runAsyncWithBlock:(void (^)(AsyncDone done)) runTestCode timeout:(NSTimeInterval) timeout;
@end

Installation

XCTestCase+RunAsync is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "XCTestCase-RunAsync"

License

XCTestCase+RunAsync is available under the MIT license. See the LICENSE file for more info.

Package Rankings
Top 18.4% on Cocoapods.org
Badges
Extracted from project README
Version License Platform