levibostian / iOSBlanky

My opinionated iOS app boilerplate
MIT License
6 stars 5 forks source link

Run unit tests on Firebase test lab #50

Closed levibostian closed 3 years ago

levibostian commented 3 years ago

After recently learning more about how GrandCentralDispatch doesn't guarantee that background thread execution may not work in a simulator, we need to run all tests on a real device.

Some back story: While writing the library Teller, I noticed in my automated integration/unit tests that when I would call the iOS SDK function Thread.isMainThread, it would randomly give me a result that was correct while other times it was incorrect. It was never consistent. I have never understood why this is.

Today, I found some resources that uncovered this mystery to me. These resources are years old which indicates that I should have found out about this a long time ago but I have found that no one seems to talk about this issue in any writing about GCD! Anyway.....

I discovered a popular open source project Async. I have used some of the logic from Async to help me better understand threading in iOS. I have read tons about threading in iOS but a popular and simple open source library is an even better resource! Looking through the project, I found that Async has automated tests written. I thought that if this project has automated tests written, it must also have these false positives like I have experienced or they have figured out something I am doing wrong.

The project has indeed talked about issues with automated tests and running the app having false positives. In various places of the project, the conclusion is that Grand Central Dispatch (GCD) does not work dependably on the simulator. Running on a physical device should fix all issues with dependable and all tests should pass all the time on a physical device.

Then, after some more searching, I have found similar findings: Threads and Queues are different in iOS 1, 2, 3

At first, I felt that running all of my tests off the simulator was the way to go. However, I don't want to have to depend on that. The main reason is because (1) developers of my apps and projects (including me) should be able to use the simulator and not have to own a device, (2) running automated tests on a CI server is important to me. Keep costs and complexity low by running tests on the simulator when I can.

levibostian commented 3 years ago

This actually doe not need to be done. I am going to close this issue in favor of this one