Token导航 LogoToken导航TokenDH.com
开发需要联网clawhub未标认证来源可访问clear审计通过

swift-xctestSwift xctest 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

4,324

周安装

182

GitHub Stars

公开资料未说明

下载量

1,514
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:swift-xctest(Swift xctest 测试)
来源仓库:https://github.com/soponcd/swift-xctest
安装命令:
openclaw skills install swift-xctest
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install swift-xctest

简介

使用 SwiftData、EventKit 和 SwiftUI 的 macOS/iOS 应用程序的 Swift 6 + XCTest 测试模式

SKILL.md

name
swift-xctest
description
Swift 6 + XCTest testing patterns for macOS/iOS apps using SwiftData, EventKit, and SwiftUI
domain
ios-macos
homepage
https://github.com/soponcd/timeflow-skills/tree/main/teams/skills/swift-xctest
metadata
clawdbot
emoji
🧩

Swift/XCTest Testing Skill

Expert-level XCTest patterns for Swift 6 macOS/iOS applications. Specialized for SwiftData, EventKit, SwiftUI, and strict concurrency.

When to Use

Use this skill when:

  • Writing XCTest for Swift 6 applications
  • Testing SwiftData models with in-memory containers
  • Testing Swift 6 actors and @MainActor isolation
  • Testing EventKit integrations
  • Testing SwiftUI views and @Observable ViewModels
  • Writing performance tests for macOS apps

Core Principles

1. SwiftData Testing Pattern

import SwiftData
import XCTest

@MainActor
final class ModelTests: XCTestCase {
    var container: ModelContainer!
    var context: ModelContext!

    override func setUp() async throws {
        try await super.setUp()
        // Use in-memory config for isolated tests
        let config = ModelConfiguration(isStoredInMemoryOnly: true)
        container = try ModelContainer(for: YourModel.self, configurations: config)
        context = container.mainContext
    }

    override func tearDown() async throws {
        container = nil
        context = nil
        try await super.tearDown()
    }
}

2. Swift 6 Actor Testing

@MainActor
final class ServiceTests: XCTestCase {
    var service: YourActor!

    override func setUp() async throws {
        try await super.setUp()
        service = YourActor()
    }

    func testActorMethod() async throws {
        // Actor-isolated tests work naturally with async
        let result = try await service.method()
        XCTAssertEqual(result, expected)
    }
}

3. Given-When-Then Pattern

func testFeature() async throws {
    // Given: Set up initial state
    let task = service.createTask(title: "Test")

    // When: Perform action
    task.complete()

    // Then: Verify result
    XCTAssertTrue(task.isCompleted)
}

4. Test Organization

@MainActor
final class FeatureTests: XCTestCase {
    // MARK: - Properties
    // Test dependencies

    // MARK: - Setup & Teardown
    // setUp/tearDown methods

    // MARK: - Unit Tests
    // Isolated tests

    // MARK: - Integration Tests
    // Tests across components

    // MARK: - Edge Cases
    // Boundary and error conditions

    // MARK: - Performance Tests
    // Performance benchmarks
}

Testing Guidelines

SwiftData Models

  • Always use ModelConfiguration(isStoredInMemoryOnly: true)
  • Mark test classes with @MainActor
  • Use try context.save() after mutations
  • Verify state with FetchDescriptor and #Predicate

Actors & Concurrency

  • Test classes interacting with actors should be @MainActor
  • Use await for all actor methods
  • Test isolation boundaries with nonisolated tests where appropriate

SwiftData Services

  • Use in-memory mode: YourService(inMemory: true)
  • Test fetch, create, update, delete operations
  • Verify FetchDescriptor queries with predicates

EventKit Mocking

  • Mock EKEventStore for isolated testing
  • Test permission handling scenarios
  • Verify EKReminder to model mapping

SwiftUI Views

  • Use @Testable import to access internal types
  • Test @Observable ViewModel behavior
  • Test state transitions and side effects

Best Practices

  1. Isolation: Each test should be independent
  2. Async-Safety: Use async/await for all async operations
  3. MainActor: Mark SwiftData tests with @MainActor
  4. Performance: Use measure blocks for critical paths
  5. Readability: Use Given-When-Then comments
  6. Organization: Group tests with // MARK: sections

Performance Testing

func testPerformance() async throws {
    measure {
        // Code to measure
        _ = service.process(data: largeDataSet)
    }
}

Common Test Patterns

Batch Query Testing

func testBatchFetchEfficiency() async throws {
    let ids = (0..<100).map { "ID-\($0)" }
    let start = Date()
    let results = service.fetch(by: ids)
    let duration = Date().timeIntervalSince(start)

    XCTAssertEqual(results.count, 100)
    XCTAssertLessThan(duration, 0.5, "Batch fetch should be fast")
}

Predicate Testing

func testPredicateFiltering() async throws {
    let descriptor = FetchDescriptor<IdentityMap>(
        predicate: #Predicate { $0.isDirty == true }
    )
    let results = try context.fetch(descriptor)
    XCTAssertEqual(results.count, expectedCount)
}

Running Tests

# Run all tests
xcodebuild test -scheme YourApp -destination 'platform=macOS'

# Run specific test
xcodebuild test -scheme YourApp -destination 'platform=macOS' \
  -only-testing:'YourAppTests/FeatureTests/testMethod'

# Run with performance output
xcodebuild test -scheme YourApp -destination 'platform=macOS' \
  -resultBundlePath ~/TestResults.xcresult

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

81.99%
按下载量换算1,241

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills