Repository navigation
This release adds per-test isolation for static mocks and a relaxed in-order verification mode. It also makes mocks much faster under load and speeds up the build plugin and generator in large projects. Mocksmith 1.1.0 requires iOS 18, macOS 15, tvOS 18, or watchOS 11.
Breaking changes
- The minimum platforms are now iOS 18, macOS 15, tvOS 18, and watchOS 11. The runtime uses
AtomicandMutexfrom the Synchronization module, which needs these releases. - Variadic stub builders such as
willReturn(),thenThrow(), andwillProduce()now require at least one value. Calling them with no arguments used to compile and then crash when the stub was registered. Now it is a compile error.
New features
- Static mocks can be isolated per test. Add
@Test(.isolatedStaticMocks)or@Suite(.isolatedStaticMocks), or wrap code inwithIsolatedStaticMocks(_:). Parallel Swift Testing tests that stub the same static member no longer overwrite each other's stubs and calls. VerifyInOrder(.relaxed)adds a relaxed mode throughInOrderMode. It ignores unrelated calls between expectations. Strict mode is still the default.
Fixes
- In-order verification now tries every occurrence of the first expectation, so it accepts a valid sequence that starts later in the call history. The failure message now says when the next call was to the expected member but its arguments didn't match.
- Swift Testing failures from
Verify,VerifyInOrder,VerifyNoMoreInteractions, and the call-history and pending-call assertions now point at the calling test, not at Mocksmith's own sources. If a test target links both test adapters, enable theMemberImportVisibilityupcoming feature, as the README describes. - Inherited protocols now resolve through imports inside
#ifblocks and through modules re-exported with@_exported import. - The build plugin now finds imports that follow a semicolon on the same line (
import A; import B). - The generator's response file is now written only when its content changes, and it counts as an input on the build-command path. Unchanged builds stay up to date.
Performance
- The generator writes one mock file per source file, so editing one protocol only regenerates and recompiles that file's mocks. In a target with 150 mocks, a rebuild after editing one mock went from 578 ms to 235 ms.
- The generator now reruns much faster when nothing changed: it scans input bytes directly, skips declaration bodies, checks its cached snapshot before parsing, and parses dependency sources only when needed. With an 800-file target and a 1500-file dependency, a no-op rerun went from 401 ms to 39 ms.
- The build plugin hashes sources with CryptoKit and skips reading files whose metadata hasn't changed. A warm import scan of swift-syntax went from 3.0 s to 0.008 s.
- Mock calls are much faster. With one stub, a call went from 5.2 µs to 0.37 µs. With 8 threads calling one member, the time per call went from 12.6 µs to 0.59 µs.
- Reading call history is now lazy, and
waitForCountonly checks new calls.CallHistory.countafter 200,000 calls went from 19 ms to about 1 ms. - Mock state is now kept in
Mutexinstead ofNSLock, so the compiler checks Sendable conformance in the runtime instead of relying on@unchecked Sendable.