Skip to main content
coreydaley.dev
Docs menu

Testing Apple apps when you don't read the code

If you don’t read the code, the tests are how you know it does what you asked. That only works if the tests check what a user would see, on the app you actually ship.

Test the effect, not the plumbing

Purrchiver once had settings that did nothing: compression level, symlink handling, metadata stripping. Every test was green, because the engine and the interface were tested separately and nothing checked the path between them. Audits found them. Now a test sets the value at the outermost layer and checks the archive that comes out: levels 1 and 9 must produce different output for 11 formats. (Placebo settings)

“Show me the line that consumes this” is a cheap review question.

Purrchiver’s tests also round-trip archives through the tools people actually use (7-Zip, Info-ZIP, tar, gzip, xz, zstd, Apple’s aa and ditto, and more) and compare SHA-256 hashes byte for byte (How Purrchiver is tested). Hard limits are tests too: extracting 1 GiB must use less than 16 MiB of memory (33 days).

Test the signed binary

The app that ships isn’t the one in the debugger. Tests read the effective entitlements of the signed app and fail on anything that shouldn’t be there, such as network access, and scan the Release build for debug-only code. Setting up that scan turned up a stray #Preview that broke the Release archive. (Test the signed binary)

“A check that never fails doesn’t tell you anything.”

So the entitlements check also asserts something that must be present, the sandbox entitlement, so it can fail. The same lesson from another project: Polyphon’s tests loaded a different build from the one that shipped, and the shipped one wasn’t encrypted.

Guard what the agent shouldn’t change

Some safety depends on a line being there, or not being there:

  • Patches to vendored C libraries, such as turning off network access in an XML parser, are pinned by tests that read the source text, with a failure message for whoever updates the library next. (Guarding vendored C)
  • Family Sharing worked in Purrchiver only because a field was ignored; a test now pins that. (One-time unlock)

Apple’s test traps

  • StoreKit tests need a logged-in session. Run from an agent’s shell, over SSH or under launchd, purchases came back unverified and every “owned” test failed. They pass in Xcode or on a runner in the GUI session, run one at a time. (StoreKit tests and the GUI launchd domain)
  • UI tests change the Mac they run on. They left it in Dark Mode, reassigned default apps and shared a sandbox container with the unit tests. (XCUITest side effects)
  • UI tests take over the screen, so they run on a separate Mac. The xcuitest-on-mini skill copies the working tree to a Mac mini and runs them there. Running them unattended took an MDM profile and an automation-mode setting. (Unattended XCUITest)
  • On iPhone, reading the clipboard from a UI test triggered the paste prompt and hung the run; the tests check the app’s “Copied” indicator instead. (Secret Store on iPhone and iPad)

After a big change, take a baseline first

A red test run after a large restructuring doesn’t tell you what broke. Run the suite on the commit before the change first, so you know which failures were already there. (Vendoring Swift packages)