View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 代码
  • 使用 AppIntentsTesting 验证你的 App Intents 采用情况

    AppIntentsTesting 是一个全新的框架,可通过 Siri、“快捷指令”和“聚焦”所使用的同款基础架构来验证你的 App Intents。探索如何执行意图、检查结果,并测试实体和查询——全程无需 UI 自动化。了解如何验证视图注释和“聚焦”索引等集成功能,助你在开发流程中尽早发现错误。

    章节

    • 0:16 - Introduction
    • 2:01 - Meet CometCal: your first test
    • 2:29 - How AppIntentsTesting works
    • 9:39 - Testing entity queries
    • 13:49 - Combining multiple intents
    • 16:27 - Test-only intents
    • 18:22 - Testing Spotlight indexing
    • 20:56 - Testing view annotations
    • 24:00 - The App Intents testing workflow
    • 25:19 - Next steps

    资源

    • Testing your App Intents code
    • App Intents Testing
      • 高清视频
      • 标清视频
  • 搜索此视频…
    • 6:48 - Your first test: execute an intent

      import AppIntentsTesting
      
      func testCreateCalendar() async throws {
          let definitions = IntentDefinitions(bundleIdentifier: "com.example.apple-samplecode.CometCal")
          let createCalendar = definitions.intents["CreateCalendarIntent"]
          let result = try await createCalendar.makeIntent(
              name: "Occupy Saturn",
              color: "red"
          ).run()
          XCTAssertEqual(try result.value.title, "Occupy Saturn")
      }
    • 12:25 - Test an entity string query

      // Testing Entity string queries
      func testEventStringQuery() async throws {
          let results = try await eventEntityDefinition
              .entities(matching: "Cosmic Ray")
      
          XCTAssertEqual(results.count, 1)
          XCTAssertEqual(try results[0].title, "Cosmic Ray Calibration")
      }
    • 13:00 - Implement the EntityStringQuery under test

      // Updated query implementation
      struct EventEntityQuery: EntityStringQuery {
          func entities(for identifiers: [EventEntity.ID]) async throws -> [EventEntity] {
      
          }
      
          func suggestedEntities() async throws -> [EventEntity] {
      
          }
      
          func entities(matching string: String) async throws -> [EventEntity] {
              try calendarManager.fetchEvents()
                  .filter { $0.title.localizedCaseInsensitiveContains(string) }
                  .map(\.entity)
          }
      }
    • 15:42 - Chain multiple intents in one test

      // Test event creation followed by update
      func testCreateAndUpdateEvent() async throws {
          let createResult = try await createEventDefinition.makeIntent(
              title: "Asteroid Dodgeball Practice",
              startDate: Date(),
              isAllDay: false,
              calendar: "Deep Space"
          ).run()
      
          XCTAssertEqual(try createResult.value.title, "Asteroid Dodgeball Practice")
      
          let updateResult = try await updateEventDefinition.makeIntent(
              title: "Asteroid Dodgeball Rules Overview",
              event: createResult.value
          ).run()
      
          XCTAssertEqual(try updateResult.value.title, "Asteroid Dodgeball Rules Overview")
      }
    • 17:45 - Make an intent test-only

      // Test-only intent: SeedSampleEventsIntent
      #if DEBUG
      struct SeedSampleEventsIntent: AppIntent {
          static let isDiscoverable = false
      
          func perform() async throws -> some IntentResult {
              // Create known list of events
              return .result()
          }
      }
      #endif
    • 20:27 - Test Spotlight indexing

      // Testing Spotlight indexing
      func testNewEventIndexedInSpotlight() async throws {
      
          let before = try await eventEntityDefinition.spotlightQuery("Supernova Viewing Party")
          XCTAssertTrue(before.isEmpty, "Event should not exist in Spotlight yet")
      
          // ... Create "Supernova Viewing Party" Event
      
          let after = try await eventEntityDefinition.spotlightQuery("Supernova Viewing Party")
          XCTAssertEqual(after.count, 1)
          XCTAssertEqual(try after[0].title, "Supernova Viewing Party")
      }
    • 22:33 - Test view annotations

      / Testing view annotations
      func testEventViewAnnotation() async throws {
          try await openEventDefinition.makeIntent(target: "Morning Launch Briefing").run()
      
          // Confirm correct event page
          let app = XCUIApplication()
          let title = app.staticTexts["Morning Launch Briefing"]
          XCTAssertTrue(title.waitForExistence(timeout: 5))
      
          let annotations = try await eventEntityDefinition.viewAnnotations()
      
          XCTAssertEqual(annotations.count, 1, "Expected exactly one view annotation")
          XCTAssertEqual(try annotations[0].entity.title, "Morning Launch Briefing")
      }
    • 0:16 - Introduction
    • AppIntentsTesting, a new framework for testing App Intents, which power Siri, Shortcuts, Spotlight, and Widgets. Outlines the agenda: getting started, framework overview, testing intents and entities, and system integrations.

    • 2:01 - Meet CometCal: your first test
    • Introduces the CometCal sample calendar app and writes a first test for CreateCalendarIntent: create a UI testing bundle, build an IntentDefinitions from the bundle id, call makeIntent with parameters, run() it on-device, and assert on the returned entity via dynamic member lookup.

    • 2:29 - How AppIntentsTesting works
    • An integration testing framework that runs your tests in a standard XCUITest bundle while the app runs in a separate process, executing intents through the full App Intents stack, with no mocks and no app-code imports (just a bundle id), giving stable, CI-friendly tests.

    • 9:39 - Testing entity queries
    • Test-driven development of an EntityStringQuery: call entities(matching:) on the entity definition, watch it fail, implement the entities(matching:) conformance on EventEntityQuery, and rerun to green, verified against Shortcuts on device.

    • 13:49 - Combining multiple intents
    • Chain intents in one test as people compose Shortcuts: run CreateEventIntent (with the runtime resolving a CalendarEntity from a string), then pass the returned EventEntity straight into UpdateEventIntent and assert the updated title.

    • 16:27 - Test-only intents
    • Focused intents that exist only for tests, to seed known state, jump directly to a view, or wrap not-yet-adopted functionality. Make any intent test-only with isDiscoverable: false and an #if DEBUG guard.

    • 18:22 - Testing Spotlight indexing
    • Write a regression test for Spotlight: spotlightQuery() returns nothing before the event exists, create it with CreateEventIntent, then assert exactly one indexed result, catching the real bug where indexing was commented out.

    • 20:56 - Testing view annotations
    • Verify the entity Siri sees on screen: open an event via OpenEventIntent, use XCUI to confirm the page, call viewAnnotations(), and assert the single ViewAnnotation's entity, surfacing a bug where the wrong EntityIdentifier (calendar id) was used.

    • 24:00 - The App Intents testing workflow
    • Where AppIntentsTesting fits: unit-test the fundamental types (actions, data, queries) first, then integration-test deeper system reaches (view annotations, Spotlight, cross-app), and still test manually with Siri and Shortcuts.

    • 25:19 - Next steps
    • Download the CometCal sample project and its full test suite, consult the AppIntentsTesting documentation for the complete API, and explore the talk on building Siri experiences with App Intents.

Developer Footer

  • 视频
  • WWDC26
  • 使用 AppIntentsTesting 验证你的 App Intents 采用情况
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner Program
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则