{"id":19554298,"url":"https://github.com/justeattakeaway/genything","last_synced_at":"2025-04-26T21:31:50.243Z","repository":{"id":39859114,"uuid":"428791508","full_name":"justeattakeaway/Genything","owner":"justeattakeaway","description":"Generate Anything","archived":false,"fork":false,"pushed_at":"2023-06-15T18:01:20.000Z","size":14400,"stargazers_count":28,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-25T22:04:19.447Z","etag":null,"topics":["faking","ios","mocking","stubbing","swift","testing"],"latest_commit_sha":null,"homepage":"https://justeattakeaway.github.io/Genything/documentation/genything","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/justeattakeaway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-16T19:43:28.000Z","updated_at":"2024-08-14T08:57:18.000Z","dependencies_parsed_at":"2023-02-11T09:45:19.470Z","dependency_job_id":null,"html_url":"https://github.com/justeattakeaway/Genything","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justeattakeaway%2FGenything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justeattakeaway%2FGenything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justeattakeaway%2FGenything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justeattakeaway%2FGenything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justeattakeaway","download_url":"https://codeload.github.com/justeattakeaway/Genything/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251057425,"owners_count":21529638,"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":["faking","ios","mocking","stubbing","swift","testing"],"created_at":"2024-11-11T04:26:44.971Z","updated_at":"2025-04-26T21:31:49.668Z","avatar_url":"https://github.com/justeattakeaway.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/justeattakeaway/Genything/main/assets/Genything-icon.png\" width=\"35%\" alt=\"Genything\" /\u003e\u003cbr/\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eGenything\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"#\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Swift-5.0+-FE8001?style=flat-square\"\n    alt=\"Swift: 5.0\"\u003e\n\u003c/a\u003e\n\u003ca href=\"#\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Platforms-iOS%20|%20tvOS%20|%20watchOS%20|%20macOS-FE8001.svg\"\n    alt=\"Platforms: iOS – tvOS – watchOS – macOS\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://cocoapods.org/pods/Genything\"\u003e\n\u003cimg src=\"https://img.shields.io/cocoapods/v/Genything.svg\"\n    alt=\"Cocoapods Compatible\"\u003e\n\u003c/a\u003e\n\u003ca href=\"#\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Swift_Package_Manager-Compatible-FE8001?style=flat-square\"\n    alt=\"Swift Package Manager Compatible\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Genything - Generate Anything\n\nGenything is a library dedicated to easy and composable generation of random data, no matter how complex.\n\nGenything can be combined with [Trickery](#Trickery) which provides a growing library of pre-made generators which mock real-world information.\n\nBoth of these libraries may be used for code testing, rapid prototyping, demo applications, ui testing, and much more. Be creative!\n\n- [Why use Genything?](#why-use-genything-)\n  * [Gen](#gen)\n  * [Arbitrary](#arbitrary)\n- [Trickery](#trickery)\n- [Examples](#examples)\n- [Mixins](#mixins)\n- [Installation](#installation)\n  * [Cocoapods](#cocoapods)\n  * [Swift Package Manager](#swift-package-manager)\n- [Credits](#credits)\n  * [Contributing](#contributing)\n  * [Inspiration](#inspiration)\n- [License](./LICENSE)\n\n## Why use Genything?\n  \n- We do not include a dependency on XCTest\n- Controllable randomness that's deterministic by default\n  - Produce the same results on CI, your colleagues machine, and your own\n- You can use these generators for anything!\n  - Create dummy data for your example apps or to rapidly prototype features\n  - Use them in your SwiftUI previews to rapidly discover edge cases\n  - Run your [screenshot](https://github.com/pointfreeco/swift-snapshot-testing) [tests](https://github.com/uber/ios-snapshot-test-case) with easy-to-use and predictable data\n  - Use your generators to unit test with [Property Based Testing](https://medium.com/criteo-engineering/introduction-to-property-based-testing-f5236229d237)\n- High test coverage\n- [100% Documented](https://justeattakeaway.github.io/Genything/documentation/genything/)\n\n### Generator\n\nThe `Generator` is the core of Genything.\n\n```swift\npublic protocol Generator {\n    associatedtype T\n    func next(_ randomSource: RandomSource) -\u003e T\n}\n```\n\nIt defines a type with a function capable of generating values using a `RandomSource`.\nThe `RandomSource` is used to track and mutate any RandomNumberGenerator instance, allowing you to control just how **much** random you would like.\n\nA generator of bools might look like this:\n\n```swift\nstruct BoolGenerator: Generator {\n    func next(_ randomSource: RandomSource) -\u003e T {\n        Bool.random(using: \u0026randomSource.rng)\n    }\n}\n```\n\nor\n\n```swift\nAnyGenerator\u003cBool\u003e { randomSource in\n    Bool.random(using: \u0026randomSource.rng)\n}\n```\n\nOr, we can take advantage of Genything's arbitrary conformance for most standard Swift types (including `Bool`)\n\n```swift\nBool.arbitrary\n```\n\nGenything provides numerous ways to [create your own Generators](https://justeattakeaway.github.io/Genything/documentation/genything/generators) under the `Generators` namespace, and the `Generator` type is [extended by many operators](https://justeattakeaway.github.io/Genything/documentation/genything/generator) which you can use to further mutate and control the resulting generator.\n\n### Arbitrary\n\nThe `Arbitary` protocol allows a Type to define a generator suitable for generating **all** of it's values.\n\nTake Swift's `Bool` as example, it's Arbitrary is defined as:\n\n```swift\nextension Bool: Arbitrary {\n    public static var arbitrary: AnyGenerator\u003cBool\u003e {\n        [true, false].arbitrary\n    }\n}\n```\n\nWe can now use this definition automatically when we are composing a more complex arbitrary type:\n\n```swift\nstruct Foo {\n  let bar: Bool\n  // ...\n}\n\nextension Transaction: Arbitrary {\n    public static var arbitrary: AnyGenerator\u003cBool\u003e {\n        Gen.compose { generate in\n          Foo(\n            bar: generate(), // Will return true/false like a coin-flip for each generated value\n            //...\n          )\n        }\n    }\n}\n```\n\nThese can then be used for invariant tests, to stub an API response, as preview data, etc...\n  \n## Trickery\n  \nGenything comes together with Trickery, a collection of generators suitable for producing pseudo-realistic data according to real-world-conditions rather than those enforced only by the type.\n\nConsider a phone number. A phone number of type `String` has rules about length, formatting, allowable characters. Whereas the arbitrary type `String` contains contains at most a definition of it's length\n\n## GenythingTest\n\nGenything provides two extensions for `XCTestCase` which we suggest that you use as your primary method for property testing.\n\n- `testAll(generator:config:file:line:body)`\n- `testAllSatisfy(generator:config:file:line:predicate)`\n\n## Examples\n\nCheckout out our [Playground guide](Example/Playground.playground)\n\n## Mixins\n\nGenything is happy when combined with other open source libraries!\n\n### Generate arbitrary SFSymbols with [SFSafeSymbols](https://github.com/piknotech/SFSafeSymbols)\n\nGenerate any [SF Symbol](https://developer.apple.com/sf-symbols/)\n\n```swift\nimport SFSafeSymbols\n\nlet sfSymbolGen: AnyGenerator\u003cSFSymbol\u003e = SFSymbol.arbitrary.map { $0.rawValue }\n```\n\n## Installation\n\n### Cocoapods\n\n```ruby\npod 'Genything'\npod 'Trickery' # Optional library of realistic fake data (Fake)\npod 'GenythingTest' # Optional extensions for property testing (testAll, testAllSatisfy)\n```\n\n### Swift Package Manager\n\nCreate a `Package.swift` file in your root directory and add:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/justeattakeaway/genything.git\", .upToNextMajor(from: \"1.0.0\"))\n]\n```\n\nThen add the packages you want to:\n\n- General -\u003e \"Frameworks and Libraries\", for an application of framework target\n- Build Phases -\u003e \"Link Binary With Libraries\", for a test target\n\n## Credits\n\nThe Genything project is owned and maintained by [SkipTheDishes](https://www.skipthedishes.com/), a [Just Eat Takeaway.com](https://www.justeattakeaway.com/) subsidiary.\n\n### Contributing\n\nPlease read the [Contribution Guide](./CONTRIBUTING.md)\n\n### Inspiration\n\nGenything stands on the shoulder of giants. Please check out these other libraries and resources!\n  \n- [SwiftCheck](https://github.com/typelift/SwiftCheck)\n- [Fakery](https://github.com/vadymmarkov/Fakery)\n- [Point-Free](https://www.pointfree.co/)'s lessons on [predictable randomness](https://github.com/pointfreeco/episode-code-samples/tree/main/0048-predictable-randomness-pt2)\n- [Kotest](https://kotest.io/)'s [Property Based Testing](https://kotest.io/docs/proptest/property-based-testing.html)\n\n## License\n\nSee: [License](./LICENSE)\n\nApache License Version 2.0, January 2004 http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusteattakeaway%2Fgenything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjusteattakeaway%2Fgenything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusteattakeaway%2Fgenything/lists"}