UITests: deinit is not called
Asked Answered
K

2

7

Why when I tests my controllers in Xcode everything is fine, but deinit methods are not called. Is it correct?

While app works normally, it is fine, but not for UITest target.

For complicated structures simulator allocate over and over more objects, and... do not deallocate it at all. So, quite often on slower machines the app sometimes quits without any reason... and tests cannot be fulfilled.

Using Xcode 8, iOS 10, macOS Sierra.

Kramatorsk answered 30/8, 2015 at 12:44 Comment(6)
Is the instance created in the test code or in the host app code?Fahey
I think, In the host App code. UITests running using host app (not sure).Wholewheat
How did you detect that deinit methods were not called? Also, if possible, please post the test code. It might help a lot.Fahey
Because I put the breakpoint inside deinit, and app didnt stop while uitesting. However deinit is called while I compile and use the app manually.Wholewheat
Sorry, my mistake... in another project init is called indeed.Wholewheat
Although it's not always the case, it could be an issue of the debugger that the execution does not pause at a breakpoint inside deinit. I created a new project and set up test for it but could not reproduce the issue. You really should update the question with a Minimal, Complete, and Verifiable example of the issue.Fahey
T
0

I can not answer your question definitively without seeing a sample of the test code, however, your case makes me suspicious of a couple things.

Basically what is happening is that the app is creating new processes for each test you run. A memory leak somewhere inside the code would be the first problem to investigate. If you are leaking memory, the testing framework spinning up a bunch of processes could cause the crash and allow that issue to fly under the radar during normal running.

Also, unless you are de-initializing the controllers explicitly through the tear down function in your test class, the process is generally just killed at the end of the test. If you want to test your reinitialization I would suggest explicitly triggering a tear down in the tests to test your memory allocation behavior. Also, the Xcode Analyze feature may be of use to you here.

If you could post a sample of your test code that would be a great help and I will edit my answer accordingly.

Torrential answered 18/10, 2016 at 1:20 Comment(0)
R
0

Make sure deinit is not empty.if its empty then it will never work.put whatever you need to deallocate and check whether its working or not.

My suggestion

 better to use dealloc method rather than using deinit.
Reichsmark answered 19/10, 2016 at 4:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.