Why is my application terminating in the middle of unit tests?
The Problem
I run my unit tests. At one point, I wait using:
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeInt开发者_运维技巧ervalSinceNow:1]];
for an NSOperationQueue to be empty. When my app reaches this line, it terminates immediately. It's run this exact same line with other tests. All tests were working perfectly recently. It also sometimes terminates my app on startup immediately.
What on earth is going on?
I've posted this for me to provide an answer in case others run into the same problem, as I've spent a full day on this and thanks to the awesomeness of git, have finally tracked down the issue.
I added:
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
into my app delegate as I wanted my app to terminate on window close. It turns out that this is the cause of the apparently random termination.
I do hide my window on startup, so I can only think this is what's causing the app to terminate immediately, although this doesn't happen every time on launch of the actual app.
I just know it was terminating consistently on that unit test, which made me think it was something to do with this code or my test. It wasn't.
I got rid of the above line and now everything works as expected.
精彩评论