Install any skill in seconds. Free to start, no credit card required.
Get Started Free →loulanyue/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.
Passed 22 of 22 test cases with the skill, and 18 of 22 without it.
and 3 more in the full report
4 fixed18 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 4 test cases the skill fixed. Same model, same prompt, with and without the skill.
We are building a data exporter actor in Swift that reads and writes local files, but we need unit tests to verify how it handles corrupt reads or write errors. Can you demonstrate a protocol-based dependency injection approach? Please include the protocol design, production and mock types, and test functions that verify error throwing.
| Checked | Without skill | With skill |
|---|---|---|
| Imports `Testing` module instead of `XCTest`. | Missed | Passed |
| Uses `#expect(throws:)` to verify error throwing in async tests. | Missed | Passed |
| Injects default protocol implementations via initializer default parameters. | Missed | Passed |
The instructions your model reads when the skill loads.
Patterns for making Swift code testable by abstracting external dependencies (file system, network, iCloud) behind small, focused protocols. Enables deterministic tests without I/O.
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
}
// Bookmark storage (e.g., for sandboxed apps)
public protocol BookmarkStorageProviding: Sendable {
func saveBookmark(_ data: Data, for key: String) throws
func loadBookmark(for key: String) throws -> Data?
}
test cases passed, vs 18 / 22 without
Published skills whose descriptions closely match this one, with their headline benchmark lift.
More skills from the same source and nearby in the registry, with their headline benchmark lift.