Individual skill

swift-protocol-di-testing

基于协议的依赖注入(Protocol-based Dependency Injection),通过精简的协议和 Swift 测试框架(Swift Testing)来模拟文件系统、网络和外部 API,编写可测试的 Swift 代码。

skills/swift-protocol-di-testing/SKILL.md

Read pinned source

Source commit dfbf9467b90dfd29bffa842c4e0a6977112900e2

What was checked

Matches the observed repository HEAD
Yes
Scanner rules are current
Yes
Repository scan complete
No
Skill scan complete
No
Observed behavior
Local scripts
Last checked
Nov 3, 2026

These are observations at the recorded commit, not a guarantee of safety. Review the source before running it.

Install this skill

Choose an agent in your Stack or copy a command below. Commands fetch the pinned commit and copy only this skill directory. Existing destinations are refused. Copying a command does not install anything.

An install command is unavailable: current rules, complete repository and skill scans, an eligible behavior level and a permitted license are required.

Repository context

Repository stars (not skill ratings)
2,024
Repository last updated
Mar 5, 2026
License
MIT

Observed agent integration: No specific integration evidence. Standard SKILL.md installation does not imply verified compatibility.

Files and excerpt

File metadata and permitted, redacted excerpts come from the recorded scan. Source links are pinned to that commit.

Browse files
Read excerpt

# 基于 Swift 协议的依赖注入(Testing)

通过将外部依赖(文件系统、网络、iCloud)抽象到精简且功能集中的协议(Protocols)后面,使 Swift 代码变得可测试。这种模式支持无需实际 I/O 即可进行确定性测试(Deterministic Tests)。

## 何时激活

- 编写访问文件系统、网络或外部 API 的 Swift 代码时
- 需要在不触发实际故障的情况下测试错误处理路径时
- 构建需要在不同环境(App、测试、SwiftUI 预览)下运行的模块时
- 使用 Swift 并发(Concurrency,如 Actor、Sendable)设计可测试架构时

## 核心模式

### 1. 定义精简且功能集中的协议