Xcode 14.1单元测试执行失败:iOS模拟器13.7无法运行测试
解决Xcode 14.1搭配iOS Simulator 13.7时Unit Test无法运行的问题
问题现象
在Xcode 14.1(Build 14B47b)、macOS 13.3.1环境下,使用iOS 13.7模拟器运行任意项目的Unit Test Target时,均出现运行失败。报错提示「系统无法安装或启动测试运行器」,底层错误为通过launchd生成进程失败,文件描述符错误(Mach错误9 - (os/kern)内存故障),具体错误日志如下:
Details Process spawn via launchd failed. Domain: NSPOSIXErrorDomain Code: 9 Failure Reason: Bad file descriptor User Info: { DVTErrorCreationDateKey = "2023-04-26 21:17:18 +0000"; IDERunOperationFailingWorker = IDELaunchiPhoneSimulatorLauncher; Session = "com.apple.CoreSimulator.SimDevice.32CA512F-AF12-4E75-B34C-D43C9AB75CDE"; } -- The operation couldn’t be completed. (Mach error 9 - (os/kern) memory failure) Domain: NSMachErrorDomain Code: 9 -- Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : { "device_model" = "iPhone12,5"; "device_osBuild" = "13.7 (17H22)"; "device_platform" = "com.apple.platform.iphonesimulator"; "launchSession_schemeCommand" = Test; "launchSession_state" = 1; "launchSession_targetArch" = "x86_64"; "operation_duration_ms" = 59; "operation_errorCode" = 9; "operation_errorDomain" = NSPOSIXErrorDomain; "operation_errorWorker" = IDELaunchiPhoneSimulatorLauncher; "operation_name" = IDERunOperationWorkerGroup; "param_consoleMode" = 0; "param_debugger_attachToExtensions" = 0; "param_debugger_attachToXPC" = 1; "param_debugger_type" = 3; "param_destination_isProxy" = 0; "param_destination_platform" = "com.apple.platform.iphonesimulator"; "param_diag_MainThreadChecker_stopOnIssue" = 0; "param_diag_MallocStackLogging_enableDuringAttach" = 0; "param_diag_MallocStackLogging_enableForXPC" = 0; "param_diag_allowLocationSimulation" = 1; "param_diag_checker_tpc_enable" = 0; "param_diag_gpu_frameCapture_enable" = 3; "param_diag_gpu_shaderValidation_enable" = 0; "param_diag_gpu_validation_enable" = 1; "param_diag_memoryGraphOnResourceException" = 0; "param_diag_queueDebugging_enable" = 1; "param_diag_runtimeProfile_generate" = 0; "param_diag_sanitizer_asan_enable" = 0; "param_diag_sanitizer_tsan_enable" = 0; "param_diag_sanitizer_tsan_stopOnIssue" = 0; "param_diag_sanitizer_ubsan_stopOnIssue" = 0; "param_diag_showNonLocalizedStrings" = 0; "param_diag_viewDebugging_enabled" = 1; "param_diag_viewDebugging_insertDylibOnLaunch" = 0; "param_install_style" = 0; "param_launcher_UID" = 2; "param_launcher_allowDeviceSensorReplayData" = 0; "param_launcher_kind" = 0; "param_launcher_style" = 0; "param_launcher_substyle" = 0; "param_runnable_appExtensionHostRunMode" = 0; "param_runnable_productType" = "com.apple.product-type.tool"; "param_runnable_type" = 1; "param_testing_launchedForTesting" = 1; "param_testing_suppressSimulatorApp" = 0; "param_testing_usingCLI" = 0; "sdk_canonicalName" = "iphonesimulator16.1"; "sdk_osVersion" = "16.1"; "sdk_variant" = iphonesimulator; } -- System Information macOS Version 13.3.1 (Build 22E261) Xcode 14.1 (21534.1) (Build 14B47b) Timestamp: 2023-04-26T23:17:18+02:00
解决方案
- 更换高版本模拟器:Xcode 14.1对iOS 13.7这类旧版本模拟器兼容性不佳,直接切换到iOS 14及以上版本(比如与当前Xcode匹配的iOS 16.1)的模拟器,大概率能解决问题。
- 重置模拟器:打开模拟器,点击顶部菜单
Device > Erase All Content and Settings,重置完成后重启Xcode再尝试运行测试。 - 清理Xcode及模拟器缓存:
- 完全关闭Xcode
- 打开终端,执行命令清除Xcode衍生数据:
rm -rf ~/Library/Developer/Xcode/DerivedData - 执行命令清除模拟器设备缓存:
rm -rf ~/Library/Developer/CoreSimulator/Devices - 重启Mac后重新打开Xcode,新建模拟器并运行测试
- 降级Xcode版本:如果必须使用iOS 13.7模拟器,建议降级到Xcode 13.x版本,该版本对iOS 13系列模拟器的支持更完善,可避免版本适配冲突。
内容的提问来源于stack exchange,提问作者Ansari
相关产品推荐
相关产品推荐

