You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action运行macOS应用测试报错:找不到'fulfillment'作用域

GitHub Action测试报错:fulfillment 找不到作用域

问题详情

在GitHub Action运行macOS应用测试时,触发如下错误:

error: cannot find 'fulfillment' in scope

使用的是XCTest的fulfillment方法,该方法自Xcode 11.0+引入,可用性标注如下:

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

已知前提:

  • 应用包支持iOS 13及以上版本;
  • GitHub Runner镜像预装Xcode 14。

排查与解决方法

1. 确认测试类继承关系与调用方式

fulfillment是XCTestCase的实例方法,必须在继承自XCTestCase的测试类中以实例方法形式调用,不能静态调用。示例正确代码:

import XCTest
@testable import YourApp

class AsyncTests: XCTestCase {
    func testSampleAsync() {
        let testExpectation = XCTestExpectation(description: "等待异步操作完成")
        
        // 执行异步任务
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
            testExpectation.fulfill()
        }
        
        // 正确调用fulfillment
        fulfillment(of: [testExpectation], timeout: 3.0)
    }
}

2. 显式指定GitHub Action使用的Xcode版本

Runner镜像虽预装Xcode 14,但可能默认指向旧版本。在Workflow中添加步骤指定版本:

jobs:
  test:
    runs-on: macos-12
    steps:
      - name: 选择Xcode 14
        run: sudo xcode-select -s /Applications/Xcode_14.app
      # 后续拉取代码、测试步骤...

3. 检查测试Target的部署目标

确保测试Target的部署目标设置为macOS 10.15+或对应平台的最低要求,避免主Target设置正确但测试Target遗漏配置。

4. 清理构建缓存

GitHub Action的缓存可能残留旧构建产物,添加清理步骤:

steps:
  - name: 清理构建缓存
    run: xcodebuild clean -scheme YourAppScheme -destination 'platform=macOS'

内容的提问来源于stack exchange,提问作者Mick F

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 13:52:35