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

大憨熊 提交于 2019-12-18 12:46:09

问题


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?


回答1:


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



回答2:


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.




回答3:


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



回答4:


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.




回答5:


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)



回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/12308297/some-of-my-unit-tests-tests-are-not-finishing-in-xcode-4-4

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