Some of my unit tests tests are not finishing in XCode 4.4
Asked Answered
W

7

28

I have seen people posting about this here and elsewhere, but I haven't found any solution that works. I am using XCode 4.4 and have a bunch of unit tests set up. I have ran them all before on this project, so I know that they do pass/fail when they are supposed to if they are actually ran.

I have about 15 test suites, and each one contains 1-7 tests. On most attempts, all of the test suites finished (and passed) except for 1 (FooTests). It gives the warning:

FooTests did not finish
    testFoo did not finish

XCode will report that testing was successful, regardless of what happens in unfinished tests. Another thing to note, sometimes it is a different test that will not finish, and sometimes multiple suites will not finish. I have not noticed a case where all tests do finish, but judging by this seemingly random behaviour I believe that it is possible.

So, is this a bug in XCode? I can't think of any other reason that tests randomly don't finish and then cause XCode to report that everything was successful. Are there any solutions?

Weslee answered 6/9, 2012 at 20:58 Comment(3)
Have found the same issue. Cleaning the target and running the test seems to resolve the issue when it pops up. I think it is a bug.Demars
Cleaning did not work for me :/Weslee
I had this problem as well, but I find that it only seems to happen when I'm not running all my tests at once. If I edit the scheme and uncheck some tests, I end up getting this "did not finish" warning when I otherwise wouldn't.Notability
F
17

I am on XCode 4.5.2. For application unit test, if your test suites finish so quick that the main application is not correctly loaded before that, you will get the warning. You can simply avoid the problem by adding a sleep at the end of your test like following. It doesn't happen for logic unit test.

 [NSThread sleepForTimeInterval:1.0];
Fairfield answered 19/12, 2012 at 3:45 Comment(3)
I've found you can actually make this 0.0 and it works just as well (and doesn't slow down your tests).Heaney
On a fast suite, I'm still seeing it with 0.0. I've put this code in my tearDown function: - (void)tearDown { static int loaded = FALSE; if (!loaded) { [NSThread sleepForTimeInterval:1.0]; loaded = TRUE; } [super tearDown]; } Double
Just came across this today, thought I was going nuts lol, thank you for the explanation!Peag
M
4

I've just had this problem with XC4.5DP4.

I had a test which does some work in a loop, and does nothing else when it falls out of the loop, and I was getting the "did not finish" error.

In an attempt to prove that the test was finishing, I added this as the very last line:

NSLog(@"done");

Not only does "done" get printed to the output - now Xcode says that the test has finished.

Seems to be a workaround... go figure.

Merete answered 12/9, 2012 at 10:21 Comment(3)
This reproduces reliably for me - if I take the logging line away again, Xcode goes back to saying "did not finish". Your mileage, however, may vary...Merete
This did nothing for me. The test that is not finishing for me involves a web request, and it might not be waiting until the request is done to run the rest of the test. But I have other tests using a web request that work fine...Weslee
I'm seeing this as well... weird.Lumberyard
K
4

I'm using XCode46-DP3 and I've just resolved this problem in my tests. I've several tests that start a web server and then execute http call to it; at the end of the test the web server is stopped. In last week these tests have begun to have the warning 'did not finish'. For me has been enough to add the following sleep at the end of these tests (precisely I've added it in the tearDown):

- (void)tearDown {
  [self.httpServer stop];
  [NSThread sleepForTimeInterval:1.0];
  self.httpServer = nil;
  self.urlComposer = nil;
}
Krum answered 17/12, 2012 at 10:2 Comment(1)
+1 for mentioning that you put it in "tearDown". just one comment: shouldn't you call [super tearDown] here?Mortmain
K
3

The problem seems that your tests terminate too quickly for Xcode to receive and parse the log messages that indicate failure or success. Sleeping for 1 second in the last test case run worked reliably for me, where 0.0 didn't. To see which test case is the last test case, check the test action in the Scheme dialog.

I created a separate WorkaroundForTestsFinishingTooFast test case, with a single method:

- (void)testThatMakesSureWeDontFinishTooFast
{
    [NSThread sleepForTimeInterval:1.0];
}

The problem is that as you add more test cases, you'll have to ensure that this test is the last method run. That means removing and adding this class from the Test action as reordering of test cases is not allowed. On the other hand, you're only delaying your entire test bundle by 1 second.

Kolomna answered 14/5, 2013 at 2:2 Comment(1)
I added the delay in the tearDown, no need to worry.Loftus
R
2

I had the same warnings in the Log Navigator. I fixed it for me.

In my project I have got 2 Schemes, one for running the project and one for the unit tests.

  1. Go to Product --> Edit Scheme...
  2. Select the UnitTest Scheme in the scheme picker
  3. Select the "Test"-Icon on the Left
  4. Change the debugger from LLDB to GDB and press OK
  5. Tests should finish now. (For me it worked fine)
Rangel answered 21/9, 2012 at 13:57 Comment(1)
That has worked for me in the past, but is not working in this case.Weslee
W
2

For me the solution was to slim down the logging output from the parts of the app that the tests were testing. I think xcode couldn't parse the tests output in time because of the other output I had throughout the app.

Walburga answered 30/5, 2013 at 21:46 Comment(0)
M
0

I had the same problem running with XCode 4.6, the reason for it, in my case, was inconsistency between the scheme and the actual unit tests in the test suits. In the scheme I had some suits checked but in their .m file some unit tests were commented.

To solve the problem: either uncomment the test or deselected the file/suit in the scheme and all shall became green again :)

for people like me that forgot how to reach the scheme these are the required steps:

  1. right click on the project name in the scheme section (right to the stop button)
  2. choose edit scheme
  3. choose the test debug
  4. click on the triangle next to the unit test project and next to each file you have a check box
  5. uncheck files that you placed unit test in comments

hope this helps

Meneses answered 14/3, 2013 at 2:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.