Skip to content

Instantly share code, notes, and snippets.

@hironytic
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save hironytic/6df7a8e203f5f26fb337 to your computer and use it in GitHub Desktop.

Select an option

Save hironytic/6df7a8e203f5f26fb337 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@interface ObjCExp1Tests : XCTestCase
@end
@implementation ObjCExp1Tests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
// test doesn't fail.
- (void)testFail1 {
__block BOOL called = NO;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
XCTFail("failed");
called = YES;
});
[NSThread sleepForTimeInterval:3];
XCTAssertTrue(called, "called");
}
// test does fail as expected.
- (void)testFail2 {
XCTestExpectation *expectation = [self expectationWithDescription:@"fail2"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
XCTFail("failed");
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:5.0 handler:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment