Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active August 29, 2015 14:01
Show Gist options
  • Save steipete/e0bbeeac9b6c776a06c2 to your computer and use it in GitHub Desktop.
Save steipete/e0bbeeac9b6c776a06c2 to your computer and use it in GitHub Desktop.
I'm using Aspects to hook into Xcode's test system to update the UI as the tests are running - this provides a nice feedback what's currently going on. https://github.com/steipete/Aspects
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController *controller = [UIViewController new];
controller.title = @"Testing...";
self.rootViewController = [[UINavigationController alloc] initWithRootViewController:controller];
self.window.rootViewController = self.rootViewController;
[self.window makeKeyAndVisible];
// Use Aspects to hook into XCTestCase to get better feedback than just the log.
[NSClassFromString(@"XCTestCase") aspect_hookSelector:NSSelectorFromString(@"invokeTest") withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> info) {
controller.title = [info.instance description];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001f]];
} error:NULL];
return YES;
}
@marcboquet
Copy link

Really cool. I tried adding a UITextView that logs the tests, would be easy to color them green/red as they progress. Not sure if super useful though.

UITextView *textView = [[UITextView alloc] initWithFrame:controller.view.bounds];
textView.font = [UIFont fontWithName:@"Courier New" size:10];
[controller.view addSubview:textView];
// Use Aspects to hook into XCTestCase to get better feedback than just the log.
[NSClassFromString(@"XCTestCase") aspect_hookSelector:NSSelectorFromString(@"invokeTest") withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> info) {
        textView.text = [textView.text stringByAppendingFormat:@"\n%@",[info.instance description]];
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001f]];
} error:NULL];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment