Search code examples
iosios-simulatorios11

All IOutlet properties are "nil" in a view controller when running test on iOS 11 Simulator


I'm getting an issue in iOS 11 Simulator where in a certain unit test, all the IBOutlet properties of a swift view controller are "nil", and where the same properties were populated in iOS 10.3 and the test was also passing.

It has the additional complication that the test passes when it is run in isolation, and also passes on the the device. It only fails on the iOS 11 simulator, and when run with all the other tests.


Solution

  • There is no explanation as to why the test fails on simulator + iOS 11 and not other configurations, but the issue was fixed by using a static method to create the second view controller. For some reason, the empty initializer ("CardViewController()") worked previously, but now requires the full create method like above.

    I was a little mistaken about how the viewController was loaded (it is loaded in the setup() method), but I also found this resource useful:

    https://www.natashatherobot.com/ios-testing-view-controllers-swift/

    It did not solve the issue, but is a useful reminder of possible race conditions in XCTest.