Latest release
1.0.0
Published August 14, 2026
Protocol mocks for Swift 6.3
Mocksmith generates protocol mocks with Swift macros. There is no Sourcery phase and no generated source to commit.
Latest release
Published August 14, 2026
One typed workflow
Attach @Mockable to a protocol. The generated peer keeps test setup tied to the protocol declaration.
import Mocksmith
import MocksmithTesting
@Mockable
protocol WeatherService {
func temperature(for city: String) async throws -> Double
}
let weather = WeatherServiceMock()
Given(weather).temperature(for: .value("Toronto")).willReturn(20)
let value = try await weather.temperature(for: "Toronto")
Verify(weather, 1).temperature(for: .value("Toronto"))Capabilities
The macro generates the mock and its Given, Perform, Calls, and Verify selectors. Swift checks member names, arguments, and result types.
An unstubbed call does not invent a result. Choose per-instance defaults only when a setup-heavy test needs them.
Mock async and typed-throwing members, actors, generics, static members, subscripts, ownership modifiers, and noncopyable inputs.
Return sequences, compute answers from arguments, suspend async calls, capture values, and verify order across mocks.
Call comparison
Every generated mock records its calls. Verify compares that history with typed matchers and a call count. Successful checks mark their calls, so VerifyNoMoreInteractions can catch anything left over.
Expected
temperature(for: "Toronto")
count: exactly 1
Recorded
temperature(for: "Toronto")
1 matching call
Platform support
Provenance you can inspect
The repository's sample target compiles the same public API shown here. Macro tests cover generated declarations, while runtime and integration tests exercise call recording, stubbing, adapters, and inherited protocols.
Start with installation, then move through the module reference.
Read the guideInspect the package, tests, and executable sample suite on GitHub.
Browse GitHub