affaan-m avatar

Swift Protocol Di Testing

This teaches protocol-based dependency injection for Swift testing, which is the right way to test code that hits the file system, network, or external APIs without actually doing I/O. You define small protocols for each external concern (file access, network calls), inject default implementations in production and mocks in tests. The examples show actors using Sendable protocols with Swift Testing, and the mock implementations let you simulate read errors or missing containers without touching real resources. It's focused on testing boundaries, not over-engineering internal types. If you're writing Swift code that needs deterministic tests for cloud sync, file operations, or API calls, this is the standard pattern.

skills.sh installs
5.4K
GitHub stars
300.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add affaan-m/ecc --skill swift-protocol-di-testing --agent claude-code

Installs into .claude/skills of the current project.

Files

Swift Protocol-Based Dependency Injection for 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.

When to Activate

  • 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)

Core Pattern

1. Define Small, Focused Protocols

Each protocol handles exactly one external concern.

// File system access
public protocol FileSystemProviding: Sendable {
    func containerURL(for purpose: Purpose) -> URL?
}

// File read/write operations
public protocol FileAccessorProviding: Sendable {
    func read(from url: URL) throws -> Data
    func write(_ data: Data, to url: URL) throws
    func fileExists(at url: URL) -> Bool
}

Sponsors

Details

Repository
github.com/affaan-m/ecc
Categories
Testing & QA, Mobile Development
First seen
Jul 14, 2026

More from affaan-m/ecc

All 263
1affaan-m avatarfsharp-testingaffaan-m/eccF# testing patterns with xUnit, FsUnit, Unquote, FsCheck property-based testing, integration tests, and test organization best practices.5.3Kskills.sh installs
2manaflow-ai avatarcmux-testingmanaflow-ai/cmuxcmux testing rules for Swift Testing, test target compilation, test wiring, and package/refactor validation. Use when adding or changing tests, touching package5.1Kskills.sh installs
3forcedotcom avatardx-devops-test-suite-assignments-configureforcedotcom/sf-skillsRecommends and manages DevOps Center test suite assignments for pipeline stages. Mode A analyzes a commit diff against assigned suite metadata to recommend rele5Kskills.sh installs
4composiohq avatarwebapp-testingcomposiohq/awesome-claude-skillsToolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing br4.9Kskills.sh installs
5dotnet avatartest-gap-analysisdotnet/skillsPerforms pseudo-mutation analysis on production code in any language to find gaps in existing tests. Use when the user asks to find weak or shallow tests, disco4.3Kskills.sh installs
6mastra-ai avatare2e-tests-studiomastra-ai/mastraREQUIRED when modifying any file in packages/playground-ui or packages/playground. Triggers on: React component creation/modification/refactoring, UI changes, n2.5Kskills.sh installs