{"id":28190445,"url":"https://github.com/easypackages/easymock","last_synced_at":"2025-06-15T08:39:41.230Z","repository":{"id":293031975,"uuid":"982366177","full_name":"EasyPackages/EasyMock","owner":"EasyPackages","description":"🎭 Lightweight Swift mocking library with async/await, delays, and error simulation","archived":false,"fork":false,"pushed_at":"2025-05-16T12:44:37.000Z","size":162,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-06-01T01:25:23.108Z","etag":null,"topics":["easypackages","mock","spm","stub","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EasyPackages.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-05-12T19:18:18.000Z","updated_at":"2025-05-16T12:44:19.000Z","dependencies_parsed_at":"2025-05-13T11:33:18.706Z","dependency_job_id":null,"html_url":"https://github.com/EasyPackages/EasyMock","commit_stats":null,"previous_names":["easypackages/easymock"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/EasyPackages/EasyMock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyPackages%2FEasyMock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyPackages%2FEasyMock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyPackages%2FEasyMock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyPackages%2FEasyMock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EasyPackages","download_url":"https://codeload.github.com/EasyPackages/EasyMock/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyPackages%2FEasyMock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259945915,"owners_count":22935929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["easypackages","mock","spm","stub","swift","testing"],"created_at":"2025-05-16T10:12:51.575Z","updated_at":"2025-06-15T08:39:41.213Z","avatar_url":"https://github.com/EasyPackages.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Banner](./doc-images/banner.jpg)\n\n[![Swift](https://github.com/EasyPackages/EasyMock/actions/workflows/swift.yml/badge.svg)](https://github.com/EasyPackages/EasyMock/actions/workflows/swift.yml)\n\n# Simulate. Test. Verify\n\nA lightweight and expressive library for unit testing in Swift — supporting `async/await`, delays, error simulation, and call tracking.\n\n## Overview\n\n**EasyMock** is a test utility designed for creating mock objects (test doubles) in Swift with minimal setup and maximum readability. \n\nIt’s ideal for testing interactions, async flows, and error handling — without boilerplate.\n\n### ✨ Features\n\n- ✅ Controlled input/output (stubbing)\n- 🔍 Call tracking (spies)\n- ⏱ Simulated delays (like network latency)\n- 🌀 Full `async/await` support\n- ❗ Error simulation (`throw`)\n- 🧪 Designed for clarity in unit tests\n\n## Why Use EasyMock?\n\n### Replace This:\n\n```swift\nfinal class AuthenticatorMock: Authenticator {\n    private(set) var authenticateCallCount = 0\n    private(set) var wasCalledWithCredential: Credential?\n    var credentialDelay: Double?\n    var authenticateStub = makeAnyAuthenticated()\n    var authenticateErrorStub: Error?\n    \n    func authenticate(_ credential: Credential) async throws -\u003e Authenticated {\n        if let delay {\n            try await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))\n        }\n        \n        if let authenticateErrorStub {\n            throw authenticateErrorStub\n        }\n        \n        authenticateCallCount += 1\n        wasCalledWithCredential = credential\n        return authenticateStub\n    }\n}\n```\n\n### With This:\n\n```swift\nstruct AuthenticatorMock: Authenticator {\n    let authenticateMocked = AsyncThrowableMock\u003cCredential, Authenticated\u003e(makeAnyAuthenticated())\n    \n    func authenticate(_ credential: Credential) async throws -\u003e Authenticated {\n        try await authenticateMocked.synchronize(credential)\n    }\n}\n```\n\n## Installation\n\n### Using Swift Package Manager\n\nSimply add a package to your project passing in https://github.com/EasyPackages/EasySymbol.\n\nIn your dependency you can add this in your Package.swift:\n\n```swift\ndependencies: [\n    .package(\n        url: \"https://github.com/EasyPackages/EasyMock.git\",\n        from: \"1.0.0\"\n    )\n]\n```\n\nIn your target:\n\n```swift\n.target(\n    name: \"YourApp\",\n    dependencies: [\"EasyMock\"]\n)\n```\n\n## Examples\n\n### Basic Mock\n\n```swift\nlet mock = Mock\u003cString, Bool\u003e(true)\nlet result = mock.synchronize(\"input\")\n\n#expect(mock.spies == [\"input\"])\n#expect(result == true)\n```\n\n### AsyncMock\n\n```swift\nlet asyncMock = AsyncMock\u003cVoid, String\u003e(\"Done\")\nasyncMock.mock(delay: 1.0)\n\nlet result = await asyncMock.synchronize()\n#expect(result == \"Done\")\n```\n\n### ThrowableMock\n\n```swift\nenum LoginError: Error { case invalid }\n\nlet mock = ThrowableMock\u003cString, Bool\u003e(false)\nmock.mock(throwing: LoginError.invalid)\n\nXCTAssertThrowsError(try mock.synchronize(\"admin\"))\n```\n\n### AsyncThrowableMock\n\n```swift\nlet asyncMock = AsyncThrowableMock\u003cString, Int\u003e(42)\nasyncMock.mock(delay: 0.5)\nasyncMock.mock(throwing: nil)\n\nlet value = try await asyncMock.synchronize(\"ping\")\nXCTAssertEqual(value, 42)\n```\n\n## Supported Platforms\n\n- iOS 13+\n- macOS 10.15+\n- Swift 5.9+\n\n## Author\n\nCreated by [Paolo Prodossimo Lopes](https://github.com/PaoloProdossimoLopes)  \nFeel free to contribute, open issues, or suggest improvements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasypackages%2Feasymock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasypackages%2Feasymock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasypackages%2Feasymock/lists"}