{"id":40968883,"url":"https://github.com/yysskk/swift-mockable","last_synced_at":"2026-04-06T05:01:50.532Z","repository":{"id":333585617,"uuid":"1137392240","full_name":"yysskk/swift-mockable","owner":"yysskk","description":"A Swift Macro that generates mock classes from protocols for testing.","archived":false,"fork":false,"pushed_at":"2026-01-25T01:55:52.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-25T21:49:41.266Z","etag":null,"topics":["mock","swift","testing"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yysskk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-19T10:04:50.000Z","updated_at":"2026-01-25T01:55:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yysskk/swift-mockable","commit_stats":null,"previous_names":["yysskk/swift-mockable"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/yysskk/swift-mockable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yysskk%2Fswift-mockable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yysskk%2Fswift-mockable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yysskk%2Fswift-mockable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yysskk%2Fswift-mockable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yysskk","download_url":"https://codeload.github.com/yysskk/swift-mockable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yysskk%2Fswift-mockable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28771467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T08:38:24.014Z","status":"ssl_error","status_checked_at":"2026-01-26T08:38:22.080Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mock","swift","testing"],"created_at":"2026-01-22T06:31:02.352Z","updated_at":"2026-04-06T05:01:50.500Z","avatar_url":"https://github.com/yysskk.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-mockable\n\n`swift-mockable` provides a `@Mockable` macro that generates protocol mocks for tests.\n\n- Generated mocks are emitted inside `#if DEBUG`.\n- Generated names follow a predictable convention (`\u003cname\u003eCallCount`, `\u003cname\u003eCallArgs`, `\u003cname\u003eHandler`).\n- `resetMock()` is generated to clear all tracking state.\n\n## Installation\n\nAdd the package:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/yysskk/swift-mockable.git\", from: \"0.1.0\")\n]\n```\n\nAdd `Mockable` to your target:\n\n```swift\n.target(\n    name: \"YourTarget\",\n    dependencies: [\"Mockable\"]\n)\n```\n\n## Quick Start\n\n```swift\nimport Mockable\n\n@Mockable\nprotocol UserService {\n    func fetchUser(id: Int) async throws -\u003e User\n    func saveUser(_ user: User) async throws\n    var currentUser: User? { get }\n    var isLoggedIn: Bool { get set }\n}\n\nlet mock = UserServiceMock()\n\nmock.fetchUserHandler = { id in\n    User(id: id, name: \"Test User\")\n}\n\nmock._currentUser = User(id: 1, name: \"Current\")\nmock.isLoggedIn = true\n\nlet user = try await mock.fetchUser(id: 42)\n\n#expect(user.id == 42)\n#expect(mock.fetchUserCallCount == 1)\n#expect(mock.fetchUserCallArgs == [42])\n\nmock.resetMock()\n#expect(mock.fetchUserCallCount == 0)\n```\n\n## What Gets Generated\n\nFor each protocol requirement, `@Mockable` generates test-friendly members:\n\n- Functions:\n  - `\u003cmethod\u003eCallCount`\n  - `\u003cmethod\u003eCallArgs`\n  - `\u003cmethod\u003eHandler`\n- Properties:\n  - Backing storage for setup (for example `_\u003cproperty\u003e`)\n  - Computed protocol-conforming property (`property`)\n- Subscripts:\n  - `subscript\u003csuffix\u003eCallCount`\n  - `subscript\u003csuffix\u003eCallArgs`\n  - `subscript\u003csuffix\u003eHandler`\n  - `subscript\u003csuffix\u003eSetHandler` for get/set subscripts\n- Utility:\n  - `resetMock()`\n\n## Supported Features\n\n- Access-level-aware generation (including `private` / `fileprivate` edge cases)\n- Sync / `async` / `throws` methods\n- Variadic parameters (captured as arrays)\n- `inout` parameters with write-back support\n- Generic methods (generic parameters are type-erased to `Any` in storage/handlers)\n- Overloaded methods (unique suffixes are added to generated names when needed)\n- Associated types (generated as `typealias`, using default type when available, otherwise `Any`)\n- Static methods and static properties\n- Get-only / get-set / optional properties\n- Get-only / get-set subscripts\n- `#if` / `#elseif` / `#else` conditional compilation inside protocols\n- Protocol inheritance (child mock inherits from first parent mock when applicable)\n- `Sendable` protocol support (`@unchecked Sendable` mock generation)\n- `Actor` protocol support (actor mock generation with nonisolated helper members)\n\n## Behavioral Notes\n\n- Return-value methods and get-only subscripts `fatalError` if their handler is not set.\n- Void-return methods and subscript setters are no-op when handler is `nil`.\n- `resetMock()` clears handlers, call counts, call arguments, and backing properties.\n- For inherited protocols, `resetMock()` calls `super.resetMock()` before resetting child members.\n\n## Diagnostics and Limitations\n\n- `@Mockable` can only be applied to protocols.\n- `@Mockable` does not accept arguments.\n- Unsupported protocol members (for example `init`) emit compile-time diagnostics.\n- Static/class subscripts are not supported.\n- For protocols with multiple parent protocols, the first parent is used as the mock superclass.\n\n## Documentation\n\n- [Docs index](docs/README.md)\n- [Advanced usage and naming rules](docs/advanced-usage.md)\n\n## Requirements\n\n- Swift 5.9, 5.10, and 6.2+\n- macOS 10.15+ / iOS 13+ / tvOS 13+ / watchOS 6+\n- `MockableLock` lock strategy:\n  - iOS 18.0+ / macOS 15.0+ / tvOS 18.0+ / watchOS 11.0+: prefers `Mutex` (`Synchronization`)\n  - Older OS versions: falls back to `LegacyLock` (`NSLock`-based)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyysskk%2Fswift-mockable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyysskk%2Fswift-mockable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyysskk%2Fswift-mockable/lists"}