testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Testing & TDD Skills

测试与TDD技能

Test-driven development workflows and testing infrastructure for Apple platform apps. Works with both new and existing codebases.
面向Apple平台应用的测试驱动开发工作流与测试基础设施,适用于新代码库与现有代码库。

When This Skill Activates

技能触发场景

Use this skill when the user:
  • Wants to do TDD (test-driven development) with AI-generated code
  • Needs to add tests before refactoring existing code
  • Wants to fix a bug using the red-green-refactor cycle
  • Needs test infrastructure (factories, mocks, contracts)
  • Asks about snapshot/visual regression testing
  • Wants to ensure AI-generated code is correct via tests
当用户有以下需求时,可使用本技能:
  • 希望结合AI生成代码进行TDD(测试驱动开发)
  • 需要在重构现有代码前添加测试
  • 希望使用红-绿-重构流程修复Bug
  • 需要搭建测试基础设施(工厂、模拟对象、契约)
  • 询问快照/视觉回归测试相关内容
  • 希望通过测试确保AI生成代码的正确性

Available Skills

可用技能

For Existing Codebases

面向现有代码库

characterization-test-generator/ Capture current behavior of existing code before refactoring. Generates tests that document what code actually does (not what it should do), giving you a safety net for AI-assisted refactoring.
tdd-bug-fix/ Reproduce-first bug fix workflow. Write a failing test that demonstrates the bug, then fix it. Ensures the bug never regresses — critical when AI generates fixes.
tdd-refactor-guard/ Pre-refactor safety checklist. Verifies test coverage exists before allowing AI to touch existing code. Prevents the "refactor without a safety net" problem.
characterization-test-generator/ 在重构前捕获现有代码的当前行为。生成的测试会记录代码的实际运行逻辑(而非预期逻辑),为AI辅助重构提供安全保障。
tdd-bug-fix/ 遵循“先复现再修复”的Bug修复工作流。先编写一个能复现Bug的失败测试,再进行修复。确保Bug不会再次出现——这在AI生成修复方案时至关重要。
tdd-refactor-guard/ 重构前的安全检查清单。在允许AI修改现有代码前,验证测试覆盖率是否达标。避免“无安全保障的重构”问题。

For New Code

面向新代码

tdd-feature/ Red-green-refactor scaffold for new features. Generates the failing test first, then guides implementation to make it pass, then refactors. The core TDD workflow.
test-contract/ Protocol/interface test suites. Define the contract (e.g., "any DataStore must handle empty state, single item, 100 items, and errors"), and it generates a test suite any implementation must pass.
tdd-feature/ 针对新功能的红-绿-重构脚手架。先生成失败的测试,再指导实现代码使其通过测试,最后进行重构。这是核心的TDD工作流。
test-contract/ 协议/接口测试套件。定义契约(例如:“任何DataStore必须处理空状态、单个条目、100个条目及错误场景”),并生成所有实现都必须通过的测试套件。

Infrastructure

基础设施类

snapshot-test-setup/ SwiftUI visual regression testing using swift-snapshot-testing. Generates snapshot test boilerplate, configuration, and CI integration.
test-data-factory/ Test fixture factories for your models. Makes writing tests faster by eliminating boilerplate data setup. Supports Builder pattern and static factory methods.
integration-test-scaffold/ Cross-module test harness with mock servers, in-memory stores, and test configuration. For testing networking + persistence + business logic together.
snapshot-test-setup/ 使用swift-snapshot-testing实现SwiftUI视觉回归测试。生成快照测试的模板代码、配置及CI集成方案。
test-data-factory/ 为模型生成测试数据工厂。通过消除重复的数据设置代码,加快测试编写速度。支持Builder模式与静态工厂方法。
integration-test-scaffold/ 包含模拟服务器、内存存储及测试配置的跨模块测试框架。用于联合测试网络、持久化与业务逻辑。

How to Use

使用方法

  1. Identify whether user is working on new code or existing code
  2. Read the relevant skill's SKILL.md for detailed workflow
  3. Detect project context (testing framework, architecture, existing tests)
  4. Generate tests following the skill's workflow
  5. Verify tests compile and run
  1. 确定用户是在处理新代码还是现有代码
  2. 阅读对应技能的SKILL.md文档获取详细工作流
  3. 检测项目上下文(测试框架、架构、现有测试情况)
  4. 遵循技能工作流生成测试
  5. 验证测试可编译并运行

Relationship to test-generator

与test-generator的关系

The
generators/test-generator/
skill generates test boilerplate (unit, integration, UI tests). These testing skills are complementary — they focus on workflows and methodology (TDD cycle, characterization testing, contracts) rather than just test file generation.
Cross-reference:
  • Use
    test-generator
    for "add tests to this class"
  • Use
    testing/tdd-feature
    for "I want to TDD this new feature"
  • Use
    testing/characterization-test-generator
    for "I need to safely refactor this"
  • Use
    testing/tdd-bug-fix
    for "fix this bug and make sure it never comes back"
generators/test-generator/
技能用于生成测试模板代码(单元测试、集成测试、UI测试)。本测试技能是其补充——我们专注于工作流与方法论(TDD周期、特征测试、契约),而非仅生成测试文件。
交叉参考:
  • 若需求是“为这个类添加测试”,使用
    test-generator
  • 若需求是“我想用TDD开发这个新功能”,使用
    testing/tdd-feature
  • 若需求是“我需要安全地重构这段代码”,使用
    testing/characterization-test-generator
  • 若需求是“修复这个Bug并确保它不再出现”,使用
    testing/tdd-bug-fix