{"id":37165995,"url":"https://github.com/steffnova/go-check","last_synced_at":"2026-01-14T19:40:18.330Z","repository":{"id":43154329,"uuid":"387835149","full_name":"steffnova/go-check","owner":"steffnova","description":"Property based testing framework for Go","archived":false,"fork":false,"pushed_at":"2023-06-08T13:27:36.000Z","size":317,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T06:31:40.954Z","etag":null,"topics":["go","golang","property-based-testing","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steffnova.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}},"created_at":"2021-07-20T15:26:47.000Z","updated_at":"2023-08-01T12:45:20.000Z","dependencies_parsed_at":"2024-06-20T05:49:08.998Z","dependency_job_id":"2cf5ecc9-72dd-4272-8966-6da0ca8dc152","html_url":"https://github.com/steffnova/go-check","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/steffnova/go-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffnova%2Fgo-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffnova%2Fgo-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffnova%2Fgo-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffnova%2Fgo-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steffnova","download_url":"https://codeload.github.com/steffnova/go-check/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffnova%2Fgo-check/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28432674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["go","golang","property-based-testing","testing"],"created_at":"2026-01-14T19:40:17.806Z","updated_at":"2026-01-14T19:40:18.321Z","avatar_url":"https://github.com/steffnova.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch2 align=\"center\"\u003e\n  \u003cimg align=\"center\" src=\"docs/resources/gopher-checking.svg\" alt=\"fast-check logo\" width=200px /\u003e \n  Checking...\n\u003c/h2\u003e\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/steffnova/go-check.svg)](https://pkg.go.dev/github.com/steffnova/go-check)\n## Intro\n\n**Go Check** is a property based testing (also known as generative testing) framework for Go programming language. In property based testing, you state facts about your code that for given precondition should always be true. Framework then tests these facts with random inputs to verify the statements. If the statement doesn't hold, framework tries to find the input with smallest complexity for which it doesn't. \n## Motivation\n\nWritting tests gives a confidence that written code works, and rewritten code doesn't break. One of the standard ways of writting tests is by defining test cases, a set of inputs for which it needs to be ensured that code under test works.\n\nWith property based testing paradigm of writting tests is shifted. Test cases are generated by the framework and writting tests comes down to defining properties that should always hold.\n## Installation\nInstallation is done as any other go package:\n```\ngo get github.com/steffnova/go-check\n```\n## Quick Start\n\nGo Check works seamlesly with **testing** package. When writting tests with go-check user doesn't specify test\ninput but input generators. These generators are then then used, through multple iterations (100 by default),\nto generate inputs and feed them to test. The example below (commutative property for addition) describes key\ncomponents for defining go-check tests:\n\n```go\npackage main_test\n\nimport (\n    \"fmt\"\n    \"testing\"\n\n    \"github.com/steffnova/go-check\"\n    \"github.com/steffnova/go-check/generator\"\n    \"github.com/steffnova/go-check/property\"\n)\n\n\n\nfunc TestAdditionCommutativity(t *testing.T) {\n    // Predicate is a function that will be used for defining a property. Predicate\n    // can have variable number of inputs, but must have only one output of error type\n    predicate := property.Predicate(func(x, y int) error {\n        // Test if changing the order of operands in addition gives the same result\n        if x+y != y+x {\n            return fmt.Errorf(\"commutativity doesn't hold for addition\")\n        }\n        return nil\n    })\n\n    // Predicate function has two inputs of type int, because of that\n    // 2 generators are required (one for \"x\" and one for \"y\"). Generators\n    // must generate int values.\n    // generator.Int accepts constraints that define range of generated values.\n    // If no constraints are specified, any int value can be generated\n    inputs := property.Inputs(\n        generator.Int(),\n        generator.Int(),                               \n    )\n\n    // Property requires a predicate function and input generators. \n    // Number of generators must match number of inputs predicate has.\n    // Generator's type with index i must match predicate's input with index i.\n    property := property.Define(\n        inputs,\n        predicate,    \n    )\n\n    // Check tests the property by feeding it with generated values\n    check.Check(t, property)\n}\n```\n\nCommutativity is one of defining properties for addition, and test above will always pass. To\ndemonstrate shrinking capabilities of go-check, following example will test commutativity for subtraction\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n\n\t\"github.com/steffnova/go-check\"\n\t\"github.com/steffnova/go-check/generator\"\n\t\"github.com/steffnova/go-check/property\"\n)\n\nfunc TestSubtractionCommutativity(t *testing.T) {\n\tcheck.Check(t, property.Define(\n\t\tproperty.Inputs(\n\t\t\tgenerator.Int(),\n\t\t\tgenerator.Int(),\n\t\t),\n\t\tproperty.Predicate(func(x, y int) error {\n\t\t\tif x-y != y-x {\n\t\t\t\treturn fmt.Errorf(\"commutativity does not hold for subtraction. \")\n\t\t\t}\n\t\t\treturn nil\n\t\t}),\n\t))\n}\n\n```\n\nCommutativity is not property of subtraction and thus above example will always fail. There are many combination of x and y for which test fails, but understing why it fails is not always visible at the first glance, especially if x and y are large values. Most of the generators also support shrinking. Shrinking is a process of reducing complexity of test inputs, and will be executed on first failing value. For this example, this means reducing the int values of x and y to smaller values, while making sure that test is still failing. Once the shrinking process is done it will present test results:\n\n```\n--- FAIL: TestSubtractionCommutativity (0.00s)\n    Check failed after 1 tests with seed: 1646421732271105000. \n    Property failed for inputs: [\n        \u003cint\u003e 0,\n        \u003cint\u003e 1\n    ]\n    Shrunk 123 time(s)\n    Failure reason: commutativity does not hold for subtraction.  \n    \n    Re-run:\n    go test -run=TestSubtractionCommutativity -seed=1646421732271105000 -iterations=100\n```\n\nTest result display the number of test ran before test failed, seed that was used to feed random number generation, smallest possible set of values for which test fails, number of times shrinking occured and failing error message. It is very important to be able to reproduce the failing test and for that reason command that can be used to reproduce test failure is printed at the end.\n\ngo-check accept two flag parameters that can be added to `go test` command:\n  - seed, seed for random number generator used by all generators\n  - iterations, total number of test go-check will perform\n\n## Documentation\n  - [Generators](/docs/generators.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffnova%2Fgo-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteffnova%2Fgo-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffnova%2Fgo-check/lists"}