Releases: gokulnair2001/SwiftMock
Releases · gokulnair2001/SwiftMock
Release list
1.0.0
Release Notes
Version 1.0.0 - Initial Release
Release Date: January 13, 2026
We're excited to announce the initial release of SwiftMock, a powerful command-line tool that automates the generation of mock implementations for Swift protocols, making unit testing faster and more efficient.
🎉 Key Features
Automatic Mock Generation
- Automatically generates mock classes from protocols marked with
/// @mockablecomment - Eliminates the need to manually write boilerplate mock code
- Supports complex method signatures including throws, async/await, and multiple parameters
Smart Call Tracking
- Call Count Tracking: Every mock method tracks how many times it was called via
{methodName}CallCount - Argument Capture: Automatically captures all arguments passed to mock methods in
{methodName}ReceivedArgumentsarray - Type-Safe: Preserves exact type information for single and multiple parameters
Flexible Handler System
- Custom Behavior: Define custom behavior for each method using
{methodName}Handlerclosures - Return Type Support: Handles methods with void and non-void return types
- Throwing Support: Full support for throwing methods with proper error propagation
Command-Line Interface
- Simple CLI: Easy-to-use command-line interface with intuitive flags
- Source Scanning: Recursively scans Swift files in specified directories
- Path Exclusion: Skip specific folders using
--excludeflag (e.g., build outputs, third-party code) - Flexible Output: Generate all mocks in a single file or separate files per protocol with
--per-file
Performance Optimizations
- Incremental Builds: Smart incremental generation only rebuilds when source files change
- Force Mode: Override incremental checks with
--forceflag when needed - Fast Parsing: Leverages Swift Syntax for efficient protocol parsing
Developer Experience
- Verbose Mode: Debug output with
-vflag for troubleshooting - Clear Error Messages: Descriptive error messages for common issues
- Xcode Integration: Seamless integration with Xcode build phases for automatic regeneration
📦 What's Included
Core Components
- SwiftMockCLI: Command-line executable with ArgumentParser integration
- SwiftMockCore: Core library containing all generation logic
- Protocol Discovery: Automatic detection of
/// @mockableprotocols - Code Generation: Swift Syntax-based mock class generation
- File Management: Intelligent file writing and directory handling
Command-Line Flags
--source/-s: Specify root directory to scan--output/-o: Define output file or directory path--exclude/-e: Comma-separated list of folders to skip--verbose/-v: Enable detailed logging--per-file: Generate separate file per protocol--force: Force regeneration on every run
🛠️ Technical Details
Requirements
- Swift 6.1 or later
- macOS 13+ (Ventura)
- Swift Package Manager
Dependencies
swift-syntax(601.0.0+): For Swift code parsing and analysisswift-argument-parser(1.3.0+): For command-line argument handling
Generated Mock Features
Each generated mock includes:
- Public initializer for easy instantiation
- Call count tracking for all methods
- Argument capture arrays with proper tuple handling
- Handler closures for custom behavior definition
- Fatal error guards for unset handlers (methods with return types)
- Proper access control (
publicmodifier)
📝 Usage Example
// 1. Mark your protocol
/// @mockable
protocol UserService {
func fetchUser(id: String) throws -> User
func deleteUser(id: String) async throws
}
// 2. Generate mocks
// $ swiftmock -s ./Sources -o ./Tests/Mocks/Mocks.swift
// 3. Use in tests
let mock = UserServiceMock()
mock.fetchUserHandler = { id in User(id: id, name: "Test") }
let user = try mock.fetchUser(id: "123")
XCTAssertEqual(mock.fetchUserCallCount, 1)🔄 Integration Options
- Manual Execution: Run from command line when needed
- Xcode Build Phase: Automatic regeneration during builds
- CI/CD Pipeline: Integrate into automated testing workflows
🎯 Design Philosophy
SwiftMock is designed with these principles in mind:
- Zero Configuration: Works out of the box with sensible defaults
- Explicit Testing: Requires explicit handler setup to avoid implicit test behavior
- Type Safety: Preserves Swift's type system throughout generated code
- Performance: Fast generation with incremental build support
- Developer Friendly: Clear errors, good documentation, and intuitive API
📖 Documentation
Complete documentation available in README.md including:
- Installation instructions
- Detailed usage guide
- Command-line flag reference
- Xcode integration guide
- Important notes and best practices
🐛 Known Limitations
- Supports macOS only
- Protocols must be explicitly marked with
/// @mockable - Generated mocks are always
public(no access control customization) - Methods with return types require handler to be set before calling
🙏 Acknowledgments
Built with ❤️ for the Swift testing community using Apple's excellent swift-syntax library.
📄 License
SwiftMock is released under the MIT License. See LICENSE for details.
For issues, feature requests, or contributions, please visit our GitHub repository.