# Introducing swift-mocking: A testing framework based on parameter packs

**URL:** <https://forums.swift.org/t/introducing-swift-mocking-a-testing-framework-based-on-parameter-packs/83463>\
**Category:** Community Showcase\
**Tags:** macros, unit-testing, parameter-packs, swift-testing\
**Created:** [November 29, 2025, 4:53pm UTC](https://forums.swift.org/t/introducing-swift-mocking-a-testing-framework-based-on-parameter-packs/83463 "2025-11-29T16:53:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielCardona](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/danielcardona/32/32291_2.png) [@DanielCardona](https://forums.swift.org/u/DanielCardona)\
**Post date:** [November 29, 2025, 4:53pm UTC](https://forums.swift.org/t/introducing-swift-mocking-a-testing-framework-based-on-parameter-packs/83463/1 "2025-11-29T16:53:48Z")

</div>

Hi, Swift community

I'm excited to share [GitHub - DanielCardonaRojas/swift-mocking: A compact swift mocking library powered by macros and parameter packs.](https://github.com/DanielCardonaRojas/swift-mocking) , a modern mocking library with a unique take.

#### What Makes It Different?

At its core, SwiftMocking uses parameter packs to preserve exact function signatures across any arity. A `Spy<String, Int, AsyncThrows, User>` represents `(String, Int) async throws -> User` with perfect type fidelity. `Spy` is `callAsFunction` to provide a natural, function-like syntax.

Effect types (`async`, `throws`) thread through as phantom types, ensuring the compiler enforces correctness.

The `@Mockable` macro generates remarkably compact protocol conformances (see [examples](https://github.com/DanielCardonaRojas/swift-mocking/blob/main/GENERATED_CODE_EXAMPLES.md)), so even writing by hand can be an option.

The library also exposes a base class `Mock` (used by the macro), that manages `Spy` creation for every protocol requirement automatically (using `@dynamicMemberLookup`).

**Key Features**

- Comprehensive protocol support: Associated types, generics, static methods, subscripts, variadic parameters, callbacks
- An extensible `ArgMatcher` with a many out of the box matchers to choose from, and `ExpressibleByLiteral` conformances for better ergonomics.
- Mockito-style API: Familiar `when()`/`verify()` syntax with sophisticated argument matching using Swift's literal protocols and range syntax
- Type-safe dynamic stubbing: Preserves concrete parameter types in closures—no casting to `Any` required
- Dual framework integration: Supports for both `XCTest` and `Testing`
- Concurrent test isolation: Uses `TaskLocal` values for safe parallel test execution
- Test-scoped defaults: Suite and test-level default values via traits (.withDefaults)
- Closure-based testing: Test dependencies directly using Spy instances without requiring protocols
- Cross-mock call verification: Verify interaction order across multiple mock objects with `verifyInOrder()`
- Descriptive error messages: Clear, actionable feedback when assertions fail.

I'd love to hear feedback from the community!
