What this thread does
Build the existing Xcode scheme for a generic iOS Simulator, then run offline client tests on a concrete simulator before claiming runtime coverage.
Do first: replace App.xcodeproj and App below with the existing project and shared scheme; use -workspace App.xcworkspace instead of -project when that is the scheme’s container. Apple documents the distinction between build, build-for-testing and test actions in TN2339.
Build and execute separate gates
1. Record xcodebuild -version and xcode-select --print-path, then inspect xcodebuild -list -project App.xcodeproj. Keep the existing project; generator adoption is a separate choice. Apple command-line FAQ. 2. Compile both configurations, keeping their outputs separate. These commands illustrate Apple’s build/configuration options and the generic simulator destination used by Bitrise’s build-for-test implementation:
xcodebuild -project App.xcodeproj -scheme App \
-configuration Debug -sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath .build/ios-debug build
xcodebuild -project App.xcodeproj -scheme App \
-configuration Release -sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath .build/ios-release build
3. Compile the test targets with build-for-testing using the same explicit scheme, configuration and generic destination. Ensure the scheme’s Test action includes the intended target. A normal app build is not evidence that XCTest bundles compile. Run test on an installed simulator UDID. Apple, Bitrise.
# Replace SIMULATOR_UDID with an installed simulator identifier.
xcodebuild -project App.xcodeproj -scheme App \
-configuration Release \
-destination 'platform=iOS Simulator,id=SIMULATOR_UDID' \
-derivedDataPath .build/ios-release-tests \
-resultBundlePath .build/ios-release-tests.xcresult test
Use a fresh result-bundle path; keep the exit status and log. Compilation cannot establish device behavior. Command-line testing, device limitations.
Make offline checks assert the client contract
Inject a session into the production client. Configure it before initialization; URLSession copies the configuration. Use a fresh ephemeral configuration with protocolClasses = [FixtureURLProtocol.self]; set urlCache = nil when testing request/decoding behavior independently of HTTP caching. FixtureURLProtocol must be your test implementation, including cancellation and unexpected-request handling. Ephemeral sessions avoid persistent network caches, cookies and credentials; they do not replace application Keychain storage. Apple configuration, custom protocols.
Recommended fixture matrix, extending Donny Wals’s request and view-model examples:
| Case | Assertion |
|---|---|
| Success and malformed JSON | Exact method, URL/path/query, encoded body and decoded result or decoding error |
| Authenticated follow/write | Expected bearer header on the intended origin; no credential in URL; expected error mapping for 401 and 403 |
| Offline and server failure | Inject URLError(.notConnectedToInternet), timeout and HTTP 500 separately; assert the intended UI state |
| Unexpected request | Fail the test and complete the request with an error; never fall through to a real connection |
| Account switch / refresh race | Hold A, finish B, release A; A must not overwrite B’s state |
For the race test, carry a request generation and account identity through the await, and compare them at the state commit on the owning actor. Cancel superseded tasks too, but cancellation alone cannot establish freshness because it is cooperative. Use controlled completions instead of timing sleeps. Apple Task.cancel).
For Keychain, inject a credential-store interface for client unit tests, then add a distinct integration test using a unique service/account namespace: add → read → update → read → delete → read absent. Recreate the store between reads to exercise persistence. Cleanup must match only those test items; SecItemDelete deletes all items matching its query. Assert each OSStatus, and distinguish item-not-found from an access or entitlement failure. Apple secrets lifecycle, deletion semantics).
Use throwing test methods and explicit XCTest assertions for fixture failures. Evaluate a throwing expression first, then assert its result; do not hide recoverable fixture errors in precondition. Preconditions terminate execution, and unchecked optimization can remove them. Swift assertions and preconditions.
Diagnostic: Failed to get length of DARWIN_USER_CACHE_DIR from confstr(3)
This warning fragment alone does not identify a Swift compile error. Read subsequent diagnostics and the final action result. DerivedData isolates build products; it does not establish cache/service recovery. SwiftedMind’s 2025-10-09 report includes both this warning and “CoreSimulatorService connection became invalid.” Treat that combination as a runner/service-access investigation before changing application code; the report does not establish a universal cache-deletion remedy.
plutil -lint checks property-list formatting, not target membership, scheme configuration, Swift types or test outcomes. Apply it to actual plist inputs; let Xcode parse and build the project. Apple’s TN3181 explicitly distinguishes plist syntax from valid privacy-manifest content.
Evidence and limits
- SwiftedMind, 2025-10-09: public xcodebuild log with cache lookup and simulator-service failures; no general fix established.
- Donny Wals, 2024-12-12: authored examples distinguish a view-model mock from request-level URLProtocol interception.
URLProtocol fixtures cover the behavior you simulate. They do not establish real TLS, redirect credential forwarding, background transfers or production connectivity. Apple excludes custom protocols from background sessions; redirect and credential behavior need separate transport-level cases. Apple protocolClasses.
Not for: App Store signing, APNs delivery or rendered XCUITest accessibility audits.
Started from a post by @editor, packaged by the editor. Original post