-
Notifications
You must be signed in to change notification settings - Fork 922
Fixed XCTest load order issues exposed in Xcode 7.3 #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed XCTest load order issues exposed in Xcode 7.3 #819
Conversation
@schluete here's the fix |
Thanks for the experimentation and the fix. If someone in the future finds a way to fix this without the |
@phatmann may want to hold off on merging this just yet, as we're still running this against our internal suite to see if other issues crop up. Will update soon once that's done, but I thought I'd just go ahead and get this out there |
Good, coz it makes me nervous to have race condition hacks :-) |
@phatmann okay so on our end things look good, but I wanna talk about this some more (because the hack and travis is failing). Is there any reason why we need to do it this way (using Is there something I'm missing? |
The teardown is done to restore the simulator to its initial state. See 927050d. |
@phatmann Ah okay. How about we just do the setup in
I've confirmed that this does get called right before the test bundle quits. |
Okay, I looked back at #596, which appears to be the discussion that led to this change, and after that and some experimentation, it's pretty clear that all of this behaves far more reliably if we rely on |
Actually, doing this in |
Okay, see the comment about why I now can't use On the plus side, this does make |
Alrighty this looks good on our end, and now it's passing travis! :) |
Looks like a good set of changes. Can you please squash the commits? Then I can merge it. |
- Moved KIFAccessibilityEnabler setup into +[KIFTestCase setUp] - Moved KIFAccessibilityEnabler teardown into a destructor function - Moved UIApplication swizzling into +[UIApplication load] category (ensures UIApplication is loaded in the runtime)
66a195a
to
9418095
Compare
Done! |
It turns out that if you don't ensure that
XCTestObservationCenter
has already loaded, then attempting to use it and add an observer subverts some sort of internal setup required to getXCTest
to spit out log lines during your tests like this:This is a really big problem if you rely on something like
xcpretty
parsing this output fromXCTest
to later generate a test report. To fix this, I moved any loading thatKIF
needed from a+(void)load
method, into+[KIFTestCase setUp]
. This fixed the issue, and now all of our importantXCTest
logging is back.Things I tried that didn't work:
+[XCTestObservationCenter initialize]
(not a good idea for other reasons, but I tried anyway)__attribute__(constructor)
+(void)load
onXCTestObservationCenter
. This appeared to work initially, but this didn't work when switching from using KIF as a static library to using it as a dynamic framework. So, I added adispatch_async
, and this appeared to work in every case. But, I found with further testing that enabling accessibility here wasn't nearly as reliable as enabling it in theXCTestObservation
method (as it was previously).Here are the docs on
+(void)load
for reference:I also went ahead and applied similar treatment I initially applied to the
KIFAccessibilityEnabler
setup, wherein I moved it into the+ (void)load
method onXCTestObservationCenter
because that's the class it needed to use (i.e. attempt 3 above), to theUIApplication
swizzling as well. In this case, we'd also want to also be sure that theUIApplication
class is loaded in the runtime before interacting with it.