Installing data during UITests

Rob Nash
2 min readOct 18, 2017

--

It is not possible to access the documents directory during a UITest (at time of writing).

I set up an App target that launched with a new scene at the root. The scene was empty, except for a single UITextField at the top.

The UITest would type a code into the UITextField that corresponded to a filename. That file, among many other files with similar coded names, were made available in the UITest App target only. A separate App target meant that I could use a wierd root controller and lots of ugly zip files, without worrying about the App Store target.

The file was looked up in the bundle, via the UITextFieldDelegate and unziped into the documents directory.

The zip files were available via source control, so continuous integration could also execute these tests.

That concludes how I solved the problem of installing files into the documents directory, during a UITest. If your interested about the three digit code that is used in these tests, read on.

The string consisted of three integers, each separated by a period. The first integer represented the ‘UITestGroupParty’, the second represented ‘UITestGroupPerformers’ and the third ‘UITestGroupPerformances’.

It was documented and understood that η represented a group of classical ballet performances for example. This understanding had to be universal across targets, so the above code was shared between the UITestApp target and the UITest target.

The UITest target used this greek letter system to instruct the App to load specific zip files.

The App target would load the corresponding zip file, using the same greek letter system.

I eventually started using CoreData, instead of the file system. Once I was using CoreData, I loaded what I needed for each test, like so.

This was easier than preparing zip files. Wish I had done this from the outset!

--

--