ios-tdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Platform 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
    ios-tdd
    or would be better handled by a more specific companion skill.
  • The request only needs a trivial answer and none of this skill's constraints or references materially help.
  • 任务与
    ios-tdd
    无关,或更适合由更专业的配套skill处理。
  • 请求仅需要简单答案,本skill的约束或参考内容无法提供实质性帮助。

Required Inputs

必填输入

  • Gather relevant project context, constraints, and the concrete problem to solve; load
    references
    only as needed.
  • Confirm the desired deliverable: design, code, review, migration plan, audit, or documentation.
  • 收集相关项目背景、约束条件以及具体要解决的问题;仅在需要时加载
    references
    内容。
  • 确认期望的交付成果:设计方案、代码、评审意见、迁移计划、审计报告或文档。

Workflow

工作流程

  • Read this
    SKILL.md
    first, then load only the referenced deep-dive files that are necessary for the task.
  • 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

产出证据

CategoryArtifactFormatExample
CorrectnessiOS TDD test planMarkdown doc per
skill-composition-standards/references/test-plan-template.md
covering Red-Green-Refactor cycles per layer
docs/ios/tdd-plan-checkout.md
CorrectnessTest pyramid coverage reportMarkdown doc showing 70/20/10 distribution and per-layer coverage
docs/ios/tdd-coverage-2026-04-16.md
类别工件格式示例
正确性iOS TDD测试计划遵循
skill-composition-standards/references/test-plan-template.md
的Markdown文档,涵盖各层的红-绿-重构循环
docs/ios/tdd-plan-checkout.md
正确性测试金字塔覆盖率报告展示70/20/10分布及分层覆盖率的Markdown文档
docs/ios/tdd-coverage-2026-04-16.md

References

参考资料

  • Use the
    references/
    directory for deep detail after reading the core workflow below.
<!-- dual-compat-end -->
  • 在阅读以下核心工作流后,如需深入细节可使用
    references/
    目录下的内容。
<!-- dual-compat-end -->

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 (
@Test
macro) for all new unit and integration tests. Use XCTest only for UI tests (XCUITest) and legacy test suites.
Dependency Injection: Protocol-based injection — no DI framework required. Define protocols for all external dependencies, inject via initialiser parameters.
TDD是一种开发流程,要求在编写功能代码之前先编写测试,遵循Red-Green-Refactor循环。每个功能都从编写失败的测试开始,完成最小化实现后再进行优化。
核心原则: 没有先编写失败的测试,就不编写生产代码。
首选框架: 所有新的单元测试和集成测试使用Swift Testing(
@Test
宏)。仅在UI测试(XCUITest)和遗留测试套件中使用XCTest。
依赖注入: 基于协议的注入——无需DI框架。为所有外部依赖定义协议,通过初始化参数注入。

Quick Reference

快速参考

TopicSectionCovers
TDD WorkflowRed-Green-RefactorStep-by-step cycle with Swift examples
Test PyramidTest PyramidUnit, integration, UI split
Swift TestingSwift Testing@Test macro, #expect, async testing
MockingProtocol MockingProtocol-based mocks, no library needed
Network MockingURLProtocol MockURLProtocol subclass for API tests
UI TestsXCUITestEnd-to-end UI testing
CI SetupCI PipelineXcode Cloud, GitHub Actions
主题章节涵盖内容
TDD工作流红-绿-重构循环带Swift示例的分步循环
测试金字塔测试金字塔单元测试、集成测试、UI测试的划分
Swift TestingSwift Testing@Test宏、#expect、异步测试
Mocking基于协议的Mocking基于协议的Mock,无需库支持
网络MockingURLProtocol Mock用于API测试的URLProtocol子类
UI测试XCUITest端到端UI测试
CI配置CI流水线Xcode Cloud、GitHub Actions

Additional Guidance

额外指引

Extended guidance for
ios-tdd
was moved to references/skill-deep-dive.md to keep this entrypoint compact and fast to load.
Use that deep dive for:
  • The Red-Green-Refactor Cycle
  • Test Pyramid (70/20/10)
  • TDD Workflow for iOS Features
  • Swift Testing Framework
  • Protocol-Based Mocking
  • Testing @Observable ViewModels
  • URLProtocol for Network Mocking
  • SwiftData / Core Data Testing
  • XCUITest for Critical Flows
  • Test Naming Convention
  • Patterns and Anti-Patterns
  • Integration with Other Skills
  • Additional deep-dive sections continue in the reference file.
ios-tdd
的扩展指引已移至references/skill-deep-dive.md,以保持本入口文件简洁、加载快速。
如需以下内容,请查看该深度指引:
  • The Red-Green-Refactor Cycle
  • Test Pyramid (70/20/10)
  • TDD Workflow for iOS Features
  • Swift Testing Framework
  • Protocol-Based Mocking
  • Testing @Observable ViewModels
  • URLProtocol for Network Mocking
  • SwiftData / Core Data Testing
  • XCUITest for Critical Flows
  • Test Naming Convention
  • Patterns and Anti-Patterns
  • Integration with Other Skills
  • 更多深度章节请查看参考文件。