{"id":19063006,"url":"https://github.com/xgouchet/elmyr","last_synced_at":"2025-04-07T13:07:50.424Z","repository":{"id":21260784,"uuid":"92030208","full_name":"xgouchet/Elmyr","owner":"xgouchet","description":"A utility to make Kotlin/Java tests random yet reproducible","archived":false,"fork":false,"pushed_at":"2024-10-17T07:25:29.000Z","size":957,"stargazers_count":83,"open_issues_count":6,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T11:08:00.857Z","etag":null,"topics":["fuzzing","hacktoberfest","hacktoberfest2020","hacktoberfest2021","hacktoberfest2022","hacktoberfest2023","hacktoberfest2024","java","kotlin","test"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgouchet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"xgouchet","custom":"https://paypal.me/xaviergouchet"}},"created_at":"2017-05-22T08:29:35.000Z","updated_at":"2024-10-17T07:25:32.000Z","dependencies_parsed_at":"2024-10-18T06:27:17.674Z","dependency_job_id":null,"html_url":"https://github.com/xgouchet/Elmyr","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgouchet%2FElmyr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgouchet%2FElmyr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgouchet%2FElmyr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgouchet%2FElmyr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgouchet","download_url":"https://codeload.github.com/xgouchet/Elmyr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"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":["fuzzing","hacktoberfest","hacktoberfest2020","hacktoberfest2021","hacktoberfest2022","hacktoberfest2023","hacktoberfest2024","java","kotlin","test"],"created_at":"2024-11-09T00:28:35.478Z","updated_at":"2025-04-07T13:07:50.400Z","avatar_url":"https://github.com/xgouchet.png","language":"Kotlin","funding_links":["https://github.com/sponsors/xgouchet","https://paypal.me/xaviergouchet"],"categories":[],"sub_categories":[],"readme":"# Elmyr\n\n\u003e Elmyr is a Kotlin library providing tools to generate “random” values, specifically useful for tests\n\n[![](https://maven-badges.herokuapp.com/maven-central/fr.xgouchet.elmyr/core/badge.svg?style=flat)](https://central.sonatype.com/namespace/fr.xgouchet.elmyr)\n[![Documentation Status](https://img.shields.io/badge/docs-wiki-brightgreen.svg)](https://github.com/xgouchet/Elmyr/wiki)\n\n[![CircleCI](https://circleci.com/gh/xgouchet/Elmyr.svg?style=shield)](https://circleci.com/github/xgouchet/Elmyr)\n[![codecov](https://codecov.io/gh/xgouchet/Elmyr/branch/master/graph/badge.svg)](https://codecov.io/gh/xgouchet/Elmyr)\n\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/xaviergouchet)\n\nBeing an adept of testing code, I write a lot of tests. One thing I noticed is that in my tests, my fake / test data always look the same. My user names are always `“Bob”` and `“Alice”`, aged `42` or `69`, with userId `4816152342` or `24601`, and eating `“spam”`, `“eggs”` and `“bacon”`. \n\nThe problem is, the more test I write, the less I'm confident in my fake values, because they're always the same. \n\nThis is where Elmyr kicks in, allowing you to create fake/fuzzy data based on a few constraints, making your test data random, and yet reproducible. \n\n## Usage\n\n### Gradle\n\n```groovy\n    dependencies {\n        // Core library\n        testCompile(\"com.github.xgouchet.Elmyr:core:1.4.1\")\n    \n        // Testing Framework Integrations\n        testCompile(\"com.github.xgouchet.Elmyr:junit4:1.4.1\")\n        testCompile(\"com.github.xgouchet.Elmyr:junit5:1.4.1\")\n        testCompile(\"com.github.xgouchet.Elmyr:spek:1.4.1\")\n    \n        // \n        testCompile(\"com.github.xgouchet.Elmyr:jvm:1.4.1\")\n    }\n```\n\n### Forging data: the `core` module\n\nYou can create an instance of the `Forge` class, and from that generate: \n\n - primitives, with basic constraints\n - Strings matching simple predicates or even Regexes\n - Any Kotlin `data class`\n - Your own custom data, by implementing the `ForgeryFactory` interface, then\n    calling the `Forge::addFactory` method.\n\n### ForgeRule for `junit4`\n\nYou can instantiate a `ForgeRule` instance, which extends the `Forge` class,\nadd factories to it, and then annotate fields on your test class with `@Forgery`.\n\n```kotlin\nclass FooTest {\n\n    @get:Rule\n    val forge = ForgeRule()\n            .withFactory(FooFactory())\n            .withFactory(BarFactory())\n\n    @Forgery\n    internal lateinit var fakeBar: Bar\n\n    @Forgery\n    lateinit var fakeFooList: List\u003cFoo\u003e\n\n    //…\n}\n```\n\n### ForgeExtension for `junit5`\n\nYou can add an extension and configure it. In addition to creating forgeries on \nfields/properties of your test class, you can inject parameters directly on your \ntest methods.\n\n```kotlin\n@ExtendWith(ForgeExtension::class)\n@ForgeConfiguration(KotlinAnnotationTest.Configurator::class)\ninternal class FooTest {\n\n    @Forgery\n    internal lateinit var fakeBar: Bar\n\n    @Forgery\n    lateinit var fakeFooList: List\u003cFoo\u003e\n\n    @Test\n    fun testSomething(@IntForgery i: Int, forge:Forge){\n        // …\n    }\n}\n```\n\n\n\n### `spek` forgeries\n\nYou can create a custom Forge instance with `spekForge` to be able to \nadd reproducibility to Spek tests.\n\n```kotlin\nclass CalculatorSpek : Spek({\n\n    val forge = spekForge(\n        seeds = mapOf(\n            \"CalculatorSpek/A calculator/addition/returns the sum of its arguments\" to 0x1337L\n        )\n    )\n\n    describe(\"A calculator\") {\n        val calculator by memoized { Calculator() }\n        \n        describe(\"addition\") {\n            it(\"returns the sum of its arguments\") {\n                val a = forge.anInt()\n                val b = forge.anInt()\n                assertEquals(calculator.add(a, b), a + b)\n            }\n        }\n    }\n})\n```\n\n## Documentation\n\nThe full documentation will be coming shortly. \nThe [Wiki](https://github.com/xgouchet/Elmyr/wiki) contains a full reference of all the packages and classes distributed.\n\n## Contributing \n\nContribution is always welcome, to know more, read our [Contributing guide](.github/CONTRIBUTING.md). \n\n## Release History\n\n### Latest Release: `1.4.1` (2024/10/19)\n\n#### `core`\n\n- Add enum forgery through reflexive factory\n- Make reflexive factory available through injection (with `@Forgery`)\n- Make reflexive factory available via JUnit4 (with `@ForgeRule`)\n- Make reflexive factory available via JUnit5 (with `@ForgeExtension`)\n- Add set forgery (thanks [@ambushwork](https://github.com/ambushwork))\n- Add list forgery with indexed lambda (thanks [@ambushwork](https://github.com/ambushwork))\n\n## Donate\n\nThis library is completely free to use and modify (as per the [License](LICENSE.md)). \nI try my best to make it as good as possible, but only do this on my free time. \nIf you want to support my work, you can click the Donate button below.\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/xaviergouchet)\n\n## Meta\n\nXavier F. Gouchet – [@xgouchet](https://twitter.com/xgouchet)\n\nDistributed under the MIT license. See [LICENSE.md](LICENSE.md) for more information.\n\n[https://github.com/xgouchet/Elymr](https://github.com/xgouchet/Elymr)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgouchet%2Felmyr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgouchet%2Felmyr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgouchet%2Felmyr/lists"}