SKILL

swift-protocol-di-testing

Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing. Use when Swift code needs testing and file system, network, or external APIs must be mocked.

Target: Software development & testing. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original English text

Topics in the source

  • Swift Protocol-Based Dependency Injection for Testing
  • When to Activate
  • Core Pattern
  • 1. Define Small, Focused Protocols
  • 2. Create Default (Production) Implementations
  • 3. Create Mock Implementations for Testing
  • 4. Inject Dependencies with Default Parameters
  • 5. Write Tests with Swift Testing

Patterns for making Swift code testable by abstracting external dependencies (file system, network, iCloud) behind small, focused protocols. Enables deterministic tests without I/O. Writing Swift code that accesses file system, network, or external APIs Need to test error handling paths without triggering real failures Building modules that work across environments (app, test, SwiftUI preview) Designing testable architecture with Swift concurrency (actors, Sendable) Each protocol handles exactly one external concern. Production code uses defaults; tests inject mocks. Single Responsibility: Each protocol should handle one concern — don't create "god protocols" with many methods Sendable conformance: Required when protocols are used across actor boundaries Default parameters: Let production code use real implementations by default; only tests need to specify mocks Error simulation: Design mocks with configurable error properties for testing failure paths Only mock boundaries: Mock external dependencies (file system, network, APIs), not internal types Creating a single large protocol that covers all external access Mocking internal types that have no external dependencies Using #if DE

This is an excerpt. Refer to the complete source and its current requirements.

Source repository
affaan-m/ECC
Source file
pi/core/skills/swift-protocol-di-testing/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Requirements

  • Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.

A small first task

先阅读原作者说明,再决定是否在自己的 AI 工具中使用。

Instructions for your AI tool

Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:43.290Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.