I'm currently having a really odd problem with iOS 12 simulators with regards to testing and I don't really know how to approach trying to solve it.
I'll do my best to explain here, but I don't fully understand what's going on so forgive me if this doesn't make a lot of sense!
I have an Xcode workspace containing a few separate projects, each of these containing some functional tests.
This workspace is also hooked up to Bitrise to run tests whenever a merge request is opened up.
All was working fine until I upgraded all the projects and targets to Swift 4.2. The upgrade itself went without hitch, with only 1 small change in the app delegate alongside settings in the project file, so I'm pretty sure nothing in the migration has caused the problem.
Previously, all tests would run and pass fine on local simulators and on Bitrise.
Now after this migration, 2 tests are failing on Bitrise and it's the same two every time.
After a bit of playing around, I managed to replicate locally and discovered that these tests would fail locally if run on an iOS 12 simulator initial launch only.
If I test on a new iOS 11.4 simulator for the first time, the tests all pass.
If I test on a new iOS 12 simulator for the first time, the two tests fail.
If I then close the iOS 12 simulator and test on it again, one of the two tests fails.
The fact that it seems to be linked to completely fresh simulator launches explains why Bitrise fails, as I imagine that runs in fresh environments with fresh simulators for each build (although maybe I'll get lucky at some point and be running on a machine that has already run an iOS 12 simulator, and so all will work fine?!).
The tests themselves are related to region monitoring. I have a mock location manager which appends regions to an array when a monitoring request for a region is sent, and removes it when a request to stop monitoring is sent.
The tests that fail are part of testStopScanningRemovesMonitoredRegions, so I add a couple of regions for monitoring, and then remove them one by one, ensuring the count of monitored regions decreases.
The assertions for adding the two regions passes.
The assertions after each removal fail.
I'm testing that a middle-man object I created correctly requests these start/stop monitoring events, rather than CLLocationManager itself.
I hope this makes some amount of sense, and sorry if it's a bit ramble; I'm just trying to include all relevant information!