ios-tdd
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlatform Notes
平台说明
- Optional helper plugins may help in some environments, but they must not be treated as required for this skill.
- 可选的辅助插件可能在某些环境中有所帮助,但不得将其视为使用本skill的必需组件。
iOS Test-Driven Development (TDD)
iOS测试驱动开发(TDD)
<!-- dual-compat-start -->
<!-- dual-compat-start -->
Use When
适用场景
- iOS Test-Driven Development standards. Enforces Red-Green-Refactor cycle, test pyramid (70/20/10), layer-specific testing strategies with XCTest and Swift Testing, and CI integration. Use when building or reviewing iOS apps with TDD methodology.
- The task needs reusable judgment, domain constraints, or a proven workflow rather than ad hoc advice.
- iOS测试驱动开发(TDD)标准。强制执行红-绿-重构(Red-Green-Refactor)循环、测试金字塔(70/20/10)、基于XCTest和Swift Testing的分层测试策略,以及CI集成。适用于采用TDD方法构建或评审iOS应用的场景。
- 任务需要可复用的判断逻辑、领域约束或经过验证的工作流,而非临时建议。
Do Not Use When
不适用场景
- The task is unrelated to or would be better handled by a more specific companion skill.
ios-tdd - The request only needs a trivial answer and none of this skill's constraints or references materially help.
- 任务与无关,或更适合由更专业的配套skill处理。
ios-tdd - 请求仅需要简单答案,本skill的约束或参考内容无法提供实质性帮助。
Required Inputs
必填输入
- Gather relevant project context, constraints, and the concrete problem to solve; load only as needed.
references - Confirm the desired deliverable: design, code, review, migration plan, audit, or documentation.
- 收集相关项目背景、约束条件以及具体要解决的问题;仅在需要时加载内容。
references - 确认期望的交付成果:设计方案、代码、评审意见、迁移计划、审计报告或文档。
Workflow
工作流程
- Read this first, then load only the referenced deep-dive files that are necessary for the task.
SKILL.md - Apply the ordered guidance, checklists, and decision rules in this skill instead of cherry-picking isolated snippets.
- Produce the deliverable with assumptions, risks, and follow-up work made explicit when they matter.
- 首先阅读本,然后仅加载完成任务所需的相关深度参考文件。
SKILL.md - 应用本skill中的有序指引、检查清单和决策规则,而非零散挑选片段内容。
- 交付成果中需明确说明重要的假设、风险以及后续工作。
Quality Standards
质量标准
- Keep outputs execution-oriented, concise, and aligned with the repository's baseline engineering standards.
- Preserve compatibility with existing project conventions unless the skill explicitly requires a stronger standard.
- Prefer deterministic, reviewable steps over vague advice or tool-specific magic.
- 输出内容需以执行为导向、简洁明了,并与代码库的基础工程标准保持一致。
- 除非skill明确要求更高标准,否则需保持与现有项目约定的兼容性。
- 优先采用可确定、可评审的步骤,而非模糊建议或工具特定的“魔法操作”。
Anti-Patterns
反模式
- Treating examples as copy-paste truth without checking fit, constraints, or failure modes.
- Loading every reference file by default instead of using progressive disclosure.
- 将示例视为可直接复制粘贴的正确内容,而不检查其适用性、约束条件或失败模式。
- 默认加载所有参考文件,而非逐步按需披露内容。
Outputs
输出内容
- A concrete result that fits the task: implementation guidance, review findings, architecture decisions, templates, or generated artifacts.
- Clear assumptions, tradeoffs, or unresolved gaps when the task cannot be completed from available context alone.
- References used, companion skills, or follow-up actions when they materially improve execution.
- 符合任务需求的具体成果:实现指引、评审发现、架构决策、模板或生成的工件。
- 当仅通过现有上下文无法完成任务时,需明确说明假设、权衡或未解决的缺口。
- 当引用内容、配套skill或后续行动能实质性提升执行效果时,需列出相关信息。
Evidence Produced
产出证据
| Category | Artifact | Format | Example |
|---|---|---|---|
| Correctness | iOS TDD test plan | Markdown doc per | |
| Correctness | Test pyramid coverage report | Markdown doc showing 70/20/10 distribution and per-layer coverage | |
| 类别 | 工件 | 格式 | 示例 |
|---|---|---|---|
| 正确性 | iOS TDD测试计划 | 遵循 | |
| 正确性 | 测试金字塔覆盖率报告 | 展示70/20/10分布及分层覆盖率的Markdown文档 | |
References
参考资料
- Use the directory for deep detail after reading the core workflow below.
references/
- 在阅读以下核心工作流后,如需深入细节可使用目录下的内容。
references/
Overview
概述
TDD is a development process where you write tests before feature code, following the Red-Green-Refactor cycle. Every feature starts with a failing test, gets minimal implementation, then is refined.
Core Principle: No production code without a failing test first.
Preferred Framework: Swift Testing ( macro) for all new unit and integration tests. Use XCTest only for UI tests (XCUITest) and legacy test suites.
@TestDependency Injection: Protocol-based injection — no DI framework required. Define protocols for all external dependencies, inject via initialiser parameters.
TDD是一种开发流程,要求在编写功能代码之前先编写测试,遵循Red-Green-Refactor循环。每个功能都从编写失败的测试开始,完成最小化实现后再进行优化。
核心原则: 没有先编写失败的测试,就不编写生产代码。
首选框架: 所有新的单元测试和集成测试使用Swift Testing(宏)。仅在UI测试(XCUITest)和遗留测试套件中使用XCTest。
@Test依赖注入: 基于协议的注入——无需DI框架。为所有外部依赖定义协议,通过初始化参数注入。
Quick Reference
快速参考
| Topic | Section | Covers |
|---|---|---|
| TDD Workflow | Red-Green-Refactor | Step-by-step cycle with Swift examples |
| Test Pyramid | Test Pyramid | Unit, integration, UI split |
| Swift Testing | Swift Testing | @Test macro, #expect, async testing |
| Mocking | Protocol Mocking | Protocol-based mocks, no library needed |
| Network Mocking | URLProtocol Mock | URLProtocol subclass for API tests |
| UI Tests | XCUITest | End-to-end UI testing |
| CI Setup | CI Pipeline | Xcode Cloud, GitHub Actions |
| 主题 | 章节 | 涵盖内容 |
|---|---|---|
| TDD工作流 | 红-绿-重构循环 | 带Swift示例的分步循环 |
| 测试金字塔 | 测试金字塔 | 单元测试、集成测试、UI测试的划分 |
| Swift Testing | Swift Testing | @Test宏、#expect、异步测试 |
| Mocking | 基于协议的Mocking | 基于协议的Mock,无需库支持 |
| 网络Mocking | URLProtocol Mock | 用于API测试的URLProtocol子类 |
| UI测试 | XCUITest | 端到端UI测试 |
| CI配置 | CI流水线 | Xcode Cloud、GitHub Actions |
Additional Guidance
额外指引
Extended guidance for was moved to references/skill-deep-dive.md to keep this entrypoint compact and fast to load.
ios-tddUse that deep dive for:
The Red-Green-Refactor CycleTest Pyramid (70/20/10)TDD Workflow for iOS FeaturesSwift Testing FrameworkProtocol-Based MockingTesting @Observable ViewModelsURLProtocol for Network MockingSwiftData / Core Data TestingXCUITest for Critical FlowsTest Naming ConventionPatterns and Anti-PatternsIntegration with Other Skills- Additional deep-dive sections continue in the reference file.
ios-tdd如需以下内容,请查看该深度指引:
The Red-Green-Refactor CycleTest Pyramid (70/20/10)TDD Workflow for iOS FeaturesSwift Testing FrameworkProtocol-Based MockingTesting @Observable ViewModelsURLProtocol for Network MockingSwiftData / Core Data TestingXCUITest for Critical FlowsTest Naming ConventionPatterns and Anti-PatternsIntegration with Other Skills- 更多深度章节请查看参考文件。