Some of my unit tests tests are not finishing in XCode 4.4

时间秒杀一切 提交于 2019-11-30 07:58:57

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];

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.

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;
}

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.

Bodo

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)

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!