登录 注册
开发者工具自动化与工作流 software-qualityswiftswift-macrostestingunit-testing
2,181
Stars
170
Forks
117
Watchers
138
Open Issues
Apache-2.0
许可证
Swift
语言
2022-12-19
创建时间
2026-11-11
最近更新

项目能做什么

现代、富于表现力的 Swift 官方测试框架库。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Swift Testing

<!--
This source file is part of the Swift.org open source project

Copyright (c) 2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->

Swift Testing is a package with expressive and intuitive APIs that make testing
your Swift code a breeze.

[![CI status badge for main branch using main toolchain](https://github.com/swiftlang/swift-testing/actions/workflows/main_using_main.yml/badge.svg?branch=main&event=push)](https://github.com/swiftlang/swift-testing/actions/workflows/main_using_main.yml)
[![CI status badge for main branch using 6.3 toolchain](https://github.com/swiftlang/swift-testing/actions/workflows/main_using_release.yml/badge.svg?branch=main&event=push)](https://github.com/swiftlang/swift-testing/actions/workflows/main_using_release.yml)

## Feature overview

### Clear, expressive API

Swift Testing has a clear and expressive API built using macros, so you can
declare complex behaviors with a small amount of code. The `#expect` API uses
Swift expressions and operators, and captures the evaluated values so you can
quickly understand what went wrong when a test fails.

```swift
import Testing

@Test func helloWorld() {
  let greeting = "Hello, world!"
  #expect(greeting == "Hello") // Expectation failed: (greeting → "Hello, world!") == "Hello"
}
```

### Custom test behaviors

You can customize the behavior of tests or test suites using traits specified in
your code. Traits can describe the runtime conditions for a test, like which
device a test should run on, or limit a test to certain operating system
versions. Traits can also help you use continuous integration effectively by
specifying execution time limits for your tests.

```swift
@Test(.enabled(if: AppFeatures.isCommentingEnabled))
func videoCommenting() async throws {
    let video = try #require(await videoLibrary.video(named: "A Beach"))
    #expect(video.comments.contains("So picturesque!"))
}
```

### Easy and flexible organization

Swift Testing provides many ways to keep your tests organized. Structure
related tests using a hierarchy of groups and subgroups. Apply tags to flexibly
manage, edit, and run tests with common characteristics across your test suite,
like tests that target a specific device or use a specific module. You can also
give tests a descriptive name so you know what they’re doing at a glance.

```swift
@Test(.tags(.metadata))
func `Check video metadata`() {
    let video = Video(fileName: "By Lake Tahoe.mov")
    let expectedMetadata = Metadata(duration: .seconds(90), filmingLocation: "California")
    #expect(video.metadata == expectedMetadata)
}
```

### Scalable coverage and execution

Parameterized tests let you write less code by running the same test over many
different inputs. And all tests integrate seamlessly with Swift Concurrency and
run in paral
阅读完整原文

商业机会分析 AI 生成

XCTest 到 Swift Testing 自动化代码迁移与重构 CLI 工具

产品构想基于 SwiftSyntax 构建的自动化重构工具,帮助拥有大型遗留代码库的企业团队将 XCTestCase、XCTAssert 系列自动转换为 Swift Testing 的 @Test、#expect 和参数化测试。
核心功能AST 级别语法重构、并发测试用例安全转换校验、批量迁移报告、私有规则自定义插件。
目标用户维护大型 iOS/macOS 遗留项目的商业团队、移动端架构师。
难度/周期中等偏高 · 2 - 3 个月 · 成本:低(主要为研发与自动化测试验证成本)
收费模式核心开源,高级规则/企业批量迁移工具采用商业授权或技术咨询服务按项目收费。
竞争风险苹果官方未来可能直接在 Xcode 内部集成基础的迁移重构建议,削弱第三方工具吸引力(AI推测)。
依据 已验证事实

跨平台 Swift Testing 结果聚合与质量看板 (SaaS)

产品构想针对在 Linux/Windows(服务端 Swift)与 macOS(客户端)混合构建的团队,提供轻量级测试报告收集、并发测试性能瓶颈追踪及 Flaky Test 分析看板。
核心功能测试标签与特征(Traits)聚合分析、跨平台失败率差异告警、参数化测试耗时热力图、GitHub Actions/GitLab CI 原生接入插件。
目标用户Server-side Swift 团队、跨平台 Swift 库维护企业、CI/CD 运维工程师。
难度/周期中等 · 3 - 4 个月 · 成本:中(云端服务器、数据库与数据存储成本)
收费模式SaaS 订阅制(按测试执行量或组织内开发者席位收费)。
竞争风险Server-side Swift 市场规模较小,垂直受众基数有限(AI推测)。
依据 数据支持的判断

基于 Swift Testing 的智能测试用例与 Mock 生成扩展

产品构想结合 LLM 与 Swift Testing 的宏特性(如参数化测试 @Test(arguments:)),为业务代码自动生成边界值测试、参数组合及断言代码的 IDE 插件与 CLI。
核心功能根据函数签名与类型自动推断边界参数、一键生成符合 Swift Testing 语法的并发测试脚手架、Mock 代码自动组装。
目标用户追求高单元测试覆盖率的企业团队、独立 iOS 开发者。
难度/周期中等 · 1 - 2 个月 · 成本:低到中(API Token 消耗及开发成本)
收费模式按月订阅制(Freemium,免费提供基础模板,高级 AI 边界推断按用量收费)。
竞争风险通用 AI 编码助手(如 GitHub Copilot、Cursor)的快速演进可能直接覆盖此垂直场景(AI推测)。
依据 尚需验证的假设
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
jaywcjlove/awesome-mac 中文介绍暂未生成
 This project is dedicated to collecting high-quality macOS
118,311 Swift
amplication/amplication 中文介绍暂未生成
Amplication brings order to the chaos of large-scale softwar
16,009 TypeScript
mumble-voip/mumble 中文介绍暂未生成
Mumble is an open-source, low-latency, high quality voice ch
8,414 C++
atinfo/awesome-test-automation 中文介绍暂未生成
A curated list of awesome test automation frameworks, tools,
7,221 -
abhivaikar/howtheytest 中文介绍暂未生成
A collection of public resources about how software companie
6,888 TypeScript
Lymphatus/caesium-image-compressor 中文介绍暂未生成
Caesium is an image compression software that helps you stor
6,475 C++
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2022-12-19,近 30 天仍在推送,发布过 19 个 Release
社区活跃Star 2,181 / Fork 170 / Issue 138(数据支持,可自行核实)
许可证Apache-2.0
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/swiftlang/swift-testing.git
cd swift-testing
# 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。