diff --git a/Source/XCTest/CDRXCTestFunctions.m b/Source/XCTest/CDRXCTestFunctions.m index 6e4298d0..4e74ecd3 100644 --- a/Source/XCTest/CDRXCTestFunctions.m +++ b/Source/XCTest/CDRXCTestFunctions.m @@ -32,10 +32,14 @@ void CDRInjectIntoXCTestRunner() { // if possible, use the new XCTestObservation protocol available in Xcode 7 Class observationCenterClass = NSClassFromString(@"XCTestObservationCenter"); if (observationCenterClass && [observationCenterClass respondsToSelector:@selector(sharedTestObservationCenter)]) { - id observationCenter = [observationCenterClass sharedTestObservationCenter]; - static CDRXCTestObserver *xcTestObserver; - xcTestObserver = [[CDRXCTestObserver alloc] init]; - [observationCenter addTestObserver:xcTestObserver]; + // Accessing the `sharedTestObservationCenter` too early causes XCTest console output to break when running + // on Xcode 7.3. Deferring adding the observer works around this issue. (rdar://25456276) + dispatch_async(dispatch_get_main_queue(), ^{ + id observationCenter = [observationCenterClass sharedTestObservationCenter]; + static CDRXCTestObserver *xcTestObserver; + xcTestObserver = [[CDRXCTestObserver alloc] init]; + [observationCenter addTestObserver:xcTestObserver]; + }); } Class testSuiteMetaClass = object_getClass(testSuiteClass); diff --git a/Spec/SpecBundle/Support/TestObservationHelper.m b/Spec/SpecBundle/Support/TestObservationHelper.m index 5317a22a..428847bf 100644 --- a/Spec/SpecBundle/Support/TestObservationHelper.m +++ b/Spec/SpecBundle/Support/TestObservationHelper.m @@ -16,7 +16,10 @@ + (void)load { if (observationCenterClass && [observationCenterClass respondsToSelector:@selector(sharedTestObservationCenter)]) { _knownTestSuites = [NSMutableArray array]; - [[observationCenterClass sharedTestObservationCenter] addTestObserver:(id)[TestObservationHelper new]]; + // See comment in CDRXCTestFunctions.m for context on the dispatch_async + dispatch_async(dispatch_get_main_queue(), ^{ + [[observationCenterClass sharedTestObservationCenter] addTestObserver:(id)[TestObservationHelper new]]; + }); } }