{"id":23388252,"url":"https://github.com/ruwatana/swifixture","last_synced_at":"2026-03-11T12:16:34.494Z","repository":{"id":264357510,"uuid":"893142866","full_name":"ruwatana/swifixture","owner":"ruwatana","description":"🧪 Fixture Automatic Generator for Swift","archived":false,"fork":false,"pushed_at":"2025-06-14T01:29:43.000Z","size":41,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T02:21:24.362Z","etag":null,"topics":["autogen","automatic","build-tool","commandline","fixture","generator","ios","macos","mock","mocking","stub","stubbing","swifixture","swift","test","testing","unittest","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruwatana.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}},"created_at":"2024-11-23T16:42:03.000Z","updated_at":"2025-06-14T01:25:22.000Z","dependencies_parsed_at":"2025-04-11T06:29:12.332Z","dependency_job_id":"47089bc9-be5a-4eab-8166-27bc910102bd","html_url":"https://github.com/ruwatana/swifixture","commit_stats":null,"previous_names":["ruwatana/swifixture"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ruwatana/swifixture","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruwatana%2Fswifixture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruwatana%2Fswifixture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruwatana%2Fswifixture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruwatana%2Fswifixture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruwatana","download_url":"https://codeload.github.com/ruwatana/swifixture/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruwatana%2Fswifixture/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30380935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"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":["autogen","automatic","build-tool","commandline","fixture","generator","ios","macos","mock","mocking","stub","stubbing","swifixture","swift","test","testing","unittest","xcode"],"created_at":"2024-12-22T02:18:21.504Z","updated_at":"2026-03-11T12:16:34.483Z","avatar_url":"https://github.com/ruwatana.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧪 Swifixture\n\n[![build](https://github.com/ruwatana/swifixture/actions/workflows/build.yml/badge.svg)](https://github.com/ruwatana/swifixture/actions/workflows/build.yml) ![Swift Version](https://img.shields.io/badge/Swift-6.0-orange.svg) ![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)\n\nSwifixture is a tool built as a Swift Package that automatically generates fixture methods for Swift.\nThis tool is inspired by [uber/mockolo](https://github.com/uber/mockolo).\n\n## 📚 Table of Contents\n\n- [📦 Installation](#-installation)\n  - [💡 Basic](#-basic)\n  - [🔧 Install in your Xcode Project](#-install-in-your-xcode-project)\n- [🚀 Usage](#-usage)\n  - [🔧 Options](#-options)\n  - [💡 Example](#-example)\n    - [Using fixturable](#using-fixturable)\n    - [Override Settings for Custom Initial Values](#override-settings-for-custom-initial-values)\n    - [Example of Generated Output](#example-of-generated-output)\n    - [Additional Imports and Testable Import](#additional-imports-and-testable-import)\n- [🚧 Work In Progress](#-work-in-progress)\n- [🤝 Contributing](#-contributing)\n- [📄 License](#-license)\n\n## 📦 Installation\n\n### 💡 Basic\n\n```bash\ngit clone https://github.com/ruwatana/swifixture.git\ncd swifixture\nswift build\n```\n\n### 🔧 Install in your Xcode Project\n\nWe also recommend to run Swifixture on your Xcode build phases by `BuildTools` package.\n(The approach using BuildTools is inspired by [nicklockwood/SwiftFormat](https://github.com/nicklockwood/SwiftFormat/blob/0.55.1/README.md#xcode-build-phase))\n\nTo set up Swifixture as an Xcode build phase, do the following:\n\n1. Create a `BuildTools` folder (if not already exists)\n\n`BuildTools` folder is a folder that contains the Swifixture executable.\n\nBecause it is a build tool, it is not included in the main package.\n\n```bash\nmkdir -p BuildTools\n```\n\n2. Create a Swift Package\n\n```bash\ncd BuildTools\nswift package init\n```\n\n3. Add Swifixture as a dependency in `Package.swift`\n\n```swift\n// Package.swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"BuildTools\",\n    platforms: [\n        .macOS(.v13)\n    ],\n    products: [\n        .library(name: \"BuildTools\", targets: [\"BuildTools\"])\n    ],\n    dependencies: [\n        .package(\n            url: \"https://github.com/ruwatana/swifixture.git\",\n            from: \"0.0.1\"\n        )\n    ],\n    targets: [\n        .target(\n            name: \"BuildTools\",\n            dependencies: [\n                .product(name: \"swifixture\", package: \"Swifixture\")\n            ]\n        )\n    ]\n)\n```\n\n4. Add a build phase to your target\n\nOpen your project in Xcode, select your target, and go to the \"Build Phases\" tab. Click the \"+\" button and add a \"Run Script\" phase. In the script field, add the following command:\n\n```bash\nif [ ! -e \"${SRCROOT}/BuildTools/.build/release/swifixture\" ]; then\n    xcrun --sdk macosx swift build -c release --package-path \"${SRCROOT}/BuildTools\"\nfi\n\n\"${SRCROOT}/BuildTools/.build/release/swifixture\"\n```\n\n[NOTE] In Xcode 15 and later, the `User Script Sandboxing` setting must be set to **NO** for this script to work properly.\n\n\u003cimg width=\"451\" alt=\"image\" src=\"https://github.com/user-attachments/assets/d2e3e200-b870-4d0f-97e3-f582a80a0d08\"\u003e\n\n## 🚀 Usage\n\nSwifixture can be executed from the command line as an executable target. The basic syntax is as follows:\n\n```bash\nswift run swifixture [options]\n```\n\n### 🔧 Options\n\n| Option                                         | Shorthand | Description                                                                                         |\n| ---------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------- |\n| `--help`                                       | `-h`      | Show help information.                                                                              |\n| `--source \u003cpath\u003e`                              | `-s`      | Specify the source file or directory path to search recursively for Swift files. Default is `./`.   |\n| `--output \u003cpath\u003e`                              | `-o`      | Specify the output file for the generated fixture methods. Default is `./Generated/Fixtures.swift`. |\n| `--additional-imports \u003cmodule1\u003e \u003cmodule2\u003e ...` |           | Specify additional module names to import. By default, Foundation is imported.                      |\n| `--testable-import \u003cmodule\u003e`                   |           | Specify a module name to testable import. By default, it is not imported.                           |\n\n### 💡 Example\n\nTo generate fixture methods for a Swift file located at `./MyStruct.swift` and output the results to `./Generated/Fixtures.swift` by default.\n\nyou can run:\n\n```bash\nswift run swifixture --source ./MyStruct.swift\n```\n\n#### Using fixturable\n\nYou can annotate your `struct` with `/// @fixturable` to enable automatic generation of fixture methods.\n\nFor example:\n\n```swift\n// MyStruct.swift\n\n/// @fixturable\nstruct User {\n    let name: String\n    let age: Int\n}\n```\n\nThis will generate fixture methods for the `User` struct on `./Generated/Fixtures.swift`, allowing you to easily create test instances.\n\n```swift\n// Generated/Fixtures.swift\n\n///\n///  @Generated by Swifixture\n///\n\nimport Foundation\n\nextension User {\n    static func fixture(\n        name: String = \"name\",\n        age: Int = 0\n    ) -\u003e Self {\n        .init(\n            name: name,\n            age: age\n        )\n    }\n}\n```\n\n#### Override Settings for Custom Initial Values\n\nYou can also specify custom initial values for properties using the `/// @fixturable(override: key = value)` annotation. For instance, if you have a custom `enum` and want to set a specific value, you can do it like this:\n\n```swift\n// MyStruct.swift\n\nenum UserRole {\n    case admin\n    case user\n}\n\n/// @fixturable(override: role = .admin)\nstruct User {\n    let name: String\n    let age: Int\n    let role: UserRole\n}\n```\n\nIn this example, the `role` property will default to `.admin` when generating fixture methods, allowing for more control over the test data.\n\n#### Example of Generated Output\n\nWhen you run the Swifixture tool with the above `User` struct, it will generate a file similar to the following:\n\n```swift\n// Generated/Fixtures.swift\n\n///\n///  @Generated by Swifixture\n///\n\nimport Foundation\n\nextension User {\n    static func fixture(\n        name: String = \"name\",\n        age: Int = 0,\n        role: UserRole = .admin\n    ) -\u003e Self {\n        .init(\n            name: name,\n            age: age,\n            role: role\n        )\n    }\n}\n```\n\n#### Additional Imports and Testable Import\n\nIf you want to include additional imports and a testable import, you can do so like this:\n\n```bash\nswift run swifixture \\\n    --source ./MyStruct.swift \\\n    --output ./Generated/Fixtures.swift \\\n    --additional-imports Combine SwiftUI \\\n    --testable-import MyModule\n```\n\nthen:\n\n```swift\n// Generated/Fixtures.swift\n\n///\n///  @Generated by Swifixture\n///\n\nimport Foundation\nimport Combine\nimport SwiftUI\n\n@testable import MyModule\n\n...\n```\n\n## 🚧 Work In Progress\n\nCurrently, Swifixture only supports auto-generating fixture methods for `struct`.\n\nAdditionally, it is limited to our defined primitive types such as `String`, `Int`, `Double`, etc.\n\nIf you want to use custom types, consider using override settings or contribute to Swifixture!\n\n## 🤝 Contributing\n\nWe welcome contributions to improve Swifixture! Please feel free to submit a pull request or open an issue for any bugs or feature requests.\n\n### Development\n\nOpen this project in Xcode and edit the code.\n\n#### Test\n\nWe have prepared a xctestplan, so you can run the test in Xcode.\n\n#### Build and Run\n\nYou can build and run Swifixture with `swift` command.\n\nWe have prepared a test source file in `./Tests/SwifixtureTests/Resources/Source.swift`.\n\n```bash\nswift build\nswift run swifixture --source ./Tests/SwifixtureTests/Resources/Source.swift\n```\n\n## 📄 License\n\nThis project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruwatana%2Fswifixture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruwatana%2Fswifixture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruwatana%2Fswifixture/lists"}