Xcode 12.3: .xcappdata specified by Test Plans not loading into simulator

298 views Asked by At

I set up a new test target for my app useing Xcode Test Plans to specify an .xcappdata file to use for each target. We run the tests in iPad & iOS Simulators, which get recreated from scratch prior to each test run.

However, Xcode never actually copies over the app data (such as com.ourCompany.ourApp.plist, and other files) from the .xcappdata file into the appropriate directories of the simulator container in ~/Library/Developer/CoreSimulator/Devices/SIMULATED_DEVICE_GUID/data/Containers/Data/Applications/OUR_APP'S_CONTAINER_GUID/.

So our tests fail because, for example, a fresh app .plist gets generated instead of using the one from our .xcappdata, resulting in UserDefaults settings values not matching expectations.

Am I doing something wrong? How can we get this to actually work...?

I have found multiple other threads, such as this one on Apple Dev Forums from four years ago, and several on Stack Overflow such as this post, that indicate that this feature has been broken since at least Xcode 6.

But... didn't they just add the per-target .xcappdata feature as part of Test Plans in Xcode 11? How could it already be broken again in Xcode 12.3? Does Apple not to have tests around their own Test Plans feature?

I hope someone can enlighten me... is it a permissions issue? A regression due to Big Sur? Do I need to add some cryptic executable (buried within the uncountable subfolders in /Applications/Xcode.app/Contents/Some/Deeply/Nested/Toolchain/usr/bin) into Security & Privacy > Privacy > Full Disk Access?

Any help would be much appreciated... thanks!

I did find the following workarounds, but neither seems very scalable:

  • set the HOME and CFFIXED_USER_HOME environment variables to $(SRC_ROOT)/path/to/myData.xcappdata/AppData/ in the test scheme (this causes that folder to now become the simulated app's container directory, resulting in these files getting modified as a result of the tests running with this as their actual home instead of the usual container location!)
  • use a script to copy over the files from the subfolders nested inside .xcappdata into the same subfolders that are nested inside of ~/Library/Developer/CoreSimulator/Devices/SOME-GUID/data/Containers/Data/Applications/ANOTHER-GUID/ (of course since these GUIDs are random and determined at test time, how to write such a script and get it to work reliably on both CI machines [that execute tests using Fastlane scripts] and local developer machines [that execute tests from within Xcode], would be pretty annoying)
0

There are 0 answers