TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
The simple test helper for asynchronous processes.
All you need to use only WAIT
and RESUME
.
- (void)testExample
{
__block NSString *response = nil;
[self requestGetAsyncronous:^(id res, NSError *error) {
response = res;
RESUME;
}];
WAIT;
XCTAssertEqualObjects(response, @"OK!");
}
When you want to notify a status (like a GHUnit).
- (void)testExample
{
[self requestGetAsyncronous:^(id res, NSError *error) {
if (error) {
RESUME_WITH(TKRGuardStatusFailure);
} else {
RESUME_WITH(TKRGuardStatusSuccess);
}
}];
WAIT_FOR(TKRGuardStatusSuccess);
}
When you want to change the default timeout interval.
// default is 1.0
[TKRGuard setDefaultTimeoutInterval:2.0];
When you want to wait some resumes
__block NSString *response1 = nil;
[self requestGetAsyncronous:^(id res, NSError *error) {
response1 = res;
RESUME;
}];
__block NSString *response2 = nil;
[self requestGetAsyncronous:^(id res, NSError *error) {
response2 = res;
RESUME;
}];
WAIT_TIMES(2);
XCTAssertEqualObjects(response1, @"1");
XCTAssertEqualObjects(response2, @"2");
When you do not want to use the shorthand macro.
#define UNUSE_TKRGUARD_SHORTHAND
- (void)testExample
{
__block id result = nil;
[self requestGetAsyncronous:^(id res, NSError *error) {
result = res;
[TKRGuard resumeForKey:@"xxx"];
}];
[TKRGuard waitWithTimeout:1.0 forKey:@"xxx"];
XCTAssertEqualObjects(response, @"OK!");
}
Add TKRGuard subdirectory to your project.
and
#import "TKRGuard.h"