UI Tests cannot use file system for state?

We were planning to use UI Tests for a work project. For my home business, since 2004, I wrote my own UI testing infrastructure that will serve as a plan B.


Anyhow, we found that our first UI test refused to work with a saved file that holds application state. To simpifly this for this discussion, lets say you have a simple file that contains a boolean. false is the default, true means the user configured the app.


In our main view controller, we look at our file and then segue to one of two destinations based upon its contents.


In the UI Test suite's setup, we added code to write out our file with desired starting state. But when the UI test is run, our app always is in the default state. Unit tests run a-ok. We have tests such as this:


assert false that the file exists

call some function to create the settings file

assert true it exists and have valid contents.


Finally, what's truly strange is that I put print statements in our main controller's viewDidAppear. That's where we load up our settings file and segue appropriately. If I put a breakpoint on that code and run our UI test, the breakpoint is hit. The line is printed to the console. But, our settings file at that point has defaults (not how it was during the suite's setup).


But... if I remove that breakpoint and just run the test, I never see the print output in the console. So it has the appearance that viewDidAppear is not being called at all.


If anyone can shed light on what may be happening, that would be great. Otherwise, we'll scrap our plans and just use a known working home-grown infrastructure.

Replies

In the UI Test suite's setup, we added code to write out our file with desired starting state.

UI test code runs in a separate process from your app, so I suspect what’s going on here is that this code is writing the file to a different container than the target app is reading from. You should be able to confirm this by logging the paths used by both the writing and reading code.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you, Quinn. That is indeed what is happening. Unlike unit tests which effectively use the main app target, the UI tests appear to create and then launch some sort of other app/process as you mention.


I've got the backup plan in place, so we're good-to-go. Perhaps in the future, the UI test bundle will use the same mechanics as a unit test bundle. Will file a feature request later today.