{"id":30207675,"url":"https://github.com/serras/kotlin-test-property","last_synced_at":"2025-08-13T16:14:05.667Z","repository":{"id":295614156,"uuid":"990646551","full_name":"serras/kotlin-test-property","owner":"serras","description":"Property testing for kotlin.test","archived":false,"fork":false,"pushed_at":"2025-07-19T16:03:42.000Z","size":170,"stargazers_count":0,"open_issues_count":7,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-19T19:59:13.181Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/serras.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-26T12:26:17.000Z","updated_at":"2025-06-22T07:42:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"9f709a8c-f21b-4801-a244-b20825ac7e21","html_url":"https://github.com/serras/kotlin-test-property","commit_stats":null,"previous_names":["serras/kotlin-test-property"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/serras/kotlin-test-property","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fkotlin-test-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fkotlin-test-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fkotlin-test-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fkotlin-test-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serras","download_url":"https://codeload.github.com/serras/kotlin-test-property/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fkotlin-test-property/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270270893,"owners_count":24555921,"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","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-08-13T16:14:03.419Z","updated_at":"2025-08-13T16:14:05.634Z","avatar_url":"https://github.com/serras.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Property Testing for `kotlin.test`\n\n`kotlin-test-property` tries to bring property-based testing to `kotlin.test`\nwith minimal dependencies and minimal machinery. In particular, you do not\nneed to install any additional plug-in to run tests from your IDE.\n\n**Property testing** builds on the idea that we should talk about properties\nwe expect of functions instead of particular runs, as unit tests do.\nStill, we need to obtain concrete values to check our properties: this is\nthe task of **generators**, which define the shape of values expected by\nthe functions under test.\n\n## Writing a test\n\nTests using `kotlin-test-property` almost always look as follows.\nIt is important to use _both_ `@Test @PropertyTest` annotations for the test\nto be correctly detected and run by the IDE.\n\n```kotlin\n@Test @PropertyTest\nfun test() = propertyTest {\n    // generate values\n    val x by int()\n    val y by list(string())\n    // assert properties of values\n    assertTrue(x \u003e 0)\n}\n```\n\nWe strongly recommend using [Power-assert](https://kotlinlang.org/docs/power-assert.html)\nto get nicer reporting once a property fails.\n\n## Describing generation\n\n`kotlin-test-property` provides a handful of basic generators for the most\ncommon types, like `int()` or `string()`. In case of generic types, you must\nprovide generators for each type argument; for example `map(int(), string())`\ngenerates maps of integers to strings.\n\nTo generate instances of your own types, the easiest way is to combine\nseveral generators using the constructor. The first option showcased below\nis often the shortest, but sometimes leads to problems with inference if\nthe class to construct is generic.\n\n```kotlin\ndata class Example(val number: Int, val strings: List\u003cString\u003e)\n\n// option 1\nval example by ::Example.by(int(), list(string()))\n// option 2\nval example by combine(int(), list(string())) { n, s -\u003e Example(n, s) }\n```\n\nIf you have a hierarchy of classes, you can use `or` or `choice` to\ndescribe the different variations. The second function allows you to\ndescribe different probabilities for each case.\n\n```kotlin\nsealed interface Example {\n    data class Number(val number: Int): Example\n    data class Thing(val string: String): Example\n}\n\n// option 1\nval example by ::Number.by(int()) or ::Thing.by(string())\n// option 2\nval example by choice(\n    2 to ::Number.by(int()),\n    3 to ::Thing.by(string())\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserras%2Fkotlin-test-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserras%2Fkotlin-test-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserras%2Fkotlin-test-property/lists"}