{"id":13413872,"url":"https://github.com/hedhyw/gherkingen","last_synced_at":"2025-10-28T11:34:59.547Z","repository":{"id":37965912,"uuid":"448326026","full_name":"hedhyw/gherkingen","owner":"hedhyw","description":"Behaviour Driven Development tests generator for Golang","archived":false,"fork":false,"pushed_at":"2024-12-29T10:23:53.000Z","size":693,"stargazers_count":81,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T09:09:43.234Z","etag":null,"topics":["bdd","bdd-framework","bdd-style","bdd-style-testing-framework","bdd-tests","behavior-driven-development","boilerplate","cucumber","cucumber-gherkin","generator","gherkin","go","golang","golang-library","golang-package","test"],"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/hedhyw.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":"2022-01-15T16:10:11.000Z","updated_at":"2025-01-31T14:09:02.000Z","dependencies_parsed_at":"2023-10-02T03:20:47.958Z","dependency_job_id":"3f3927f1-1389-4249-9589-24a1dc46ac97","html_url":"https://github.com/hedhyw/gherkingen","commit_stats":{"total_commits":102,"total_committers":5,"mean_commits":20.4,"dds":0.3431372549019608,"last_synced_commit":"c3229ea55bcccba5b6217da2c84ace2ba3194a8a"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Fgherkingen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Fgherkingen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Fgherkingen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Fgherkingen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedhyw","download_url":"https://codeload.github.com/hedhyw/gherkingen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471519,"owners_count":20944158,"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":["bdd","bdd-framework","bdd-style","bdd-style-testing-framework","bdd-tests","behavior-driven-development","boilerplate","cucumber","cucumber-gherkin","generator","gherkin","go","golang","golang-library","golang-package","test"],"created_at":"2024-07-30T20:01:51.665Z","updated_at":"2025-10-28T11:34:54.501Z","avatar_url":"https://github.com/hedhyw.png","language":"Go","funding_links":[],"categories":["Testing","测试","Go","Template Engines"],"sub_categories":["Testing Frameworks","HTTP客户端","HTTP Clients"],"readme":"# gherkingen\n\n![Version](https://img.shields.io/github/v/tag/hedhyw/gherkingen)\n![Build Status](https://github.com/hedhyw/gherkingen/actions/workflows/check.yml/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hedhyw/gherkingen)](https://goreportcard.com/report/github.com/hedhyw/gherkingen)\n[![Coverage Status](https://coveralls.io/repos/github/hedhyw/gherkingen/badge.svg?branch=main)](https://coveralls.io/github/hedhyw/gherkingen?branch=main)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n\n**It's a Behaviour Driven Development (BDD) tests generator for Golang.**\n\n![Gopher Gherkingen BDD testing golang](./assets/gopher.png)\n\nIt accepts a `*.feature` [Cucumber/Gherkin](https://cucumber.io/docs/gherkin/reference/) file and generates a test boilerplate. All that remains is to change the tests a little. The generator supports `go generate` and `go test` for generated tests.\n\nThe generator is very customizable, it is possible to customize an output for any golang [testing framework](#frameworks-support) or even for [another language](#language-support).\n\n# What is for?\n## Simple example\n\n**Given** [feature](internal/generator/examples/readme.feature) [[reference](https://cucumber.io/docs/gherkin/reference/)]:\n```feature\nFeature: Application command line tool\n  Scenario Outline: User wants to see usage information\n    When the application is started with \u003cflag\u003e\n    Then usage should be printed \u003cprinted\u003e\n    And exit status should be \u003cexit_status\u003e\n    Examples:\n    | \u003cflag\u003e   | \u003cexit_status\u003e | \u003cprinted\u003e |\n    | --help   |       0       | true      |\n    | -help    |       0       | true      |\n    | -invalid |       1       | false     |\n```\n\n**Then** this generator writes a [golang](internal/generator/examples/readme.feature_test.go) output (`gerkingen readme.feature \u003e readme.feature_test.go`):\n\n```go\nfunc TestApplicationCommandLineTool(t *testing.T) {\n\tt.Parallel()\n\n\tt.Run(\"User wants to see usage information\", func(t *testing.T) {\n\t\tt.Parallel()\n\n\t\ttype testCase struct {\n\t\t\tFlag       string `field:\"\u003cflag\u003e\"`\n\t\t\tExitStatus int    `field:\"\u003cexit_status\u003e\"`\n\t\t\tPrinted    bool   `field:\"\u003cprinted\u003e\"`\n\t\t}\n\n\t\ttestCases := map[string]testCase{\n\t\t\t\"--help_0_true\":    {\"--help\", 0, true},\n\t\t\t\"-help_0_true\":     {\"-help\", 0, true},\n\t\t\t\"-invalid_1_false\": {\"-invalid\", 1, false},\n\t\t}\n\n\t\tfor name, testCase := range testCases {\n\t\t\ttestCase := testCase\n\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\tt.Parallel()\n\n\t\t\t\t// When the application is started with \u003cflag\u003e.\n\n\t\t\t\t// Then usage should be printed \u003cprinted\u003e.\n\n\t\t\t\t// And exit status should be \u003cexit_status\u003e.\n\n\t\t\t})\n\t\t}\n\t})\n}\n```\n\n**Example** implementation:\n\n```go\nt.Run(name, func(t *testing.T) {\n\tt.Parallel()\n\n\t// When flag \u003cflag\u003e is provided.\n\targuments := []string{testCase.Flag}\n\n\t// Then usage should be printed \u003cprinted\u003e.\n\tvar output string\n\toutput, exitStatus = runApp(t, arguments)\n\tassert.Equal(t, testCase.Printed, strings.Contains(output, \"usage\"))\n\n\t// And exit status should be \u003cexit_status\u003e.\n\tassert.Equal(t, testCase.ExitStatus, exitStatus)\n})\n```\n\n## More advanced example\n\nSee [internal/app/app.feature](internal/app/app.feature) and [internal/app/app_test.go](internal/app/app_test.go).\n\n## Version 3 changes\n\n1. Simplified template is set by default. In order to use the default template from the previous versions, provide the following flag `-template @/std.struct.v1.go.tmpl`.\n2. All tests will have `t.Parallel` by default. This behaviour can be disabled by providing the flag `-disable-go-parallel`.\n\n## Version 4 changes\n\n1. Removed template \"std.struct.v1.go.tmpl\".\n\n# Install\n\n## Package\n\nLatest DEB and RPM packages are available on [the releases page](https://github.com/hedhyw/gherkingen/releases/latest).\n\n## MacOS/Linux HomeBrew\n\n```sh\n# Install the package using HomeBrew.\nbrew install hedhyw/gherkingen/gherkingen\n\n# Check that the generator is working.\ngherkingen -help\n```\n\n## Standalone Binary\n\nDownload latest archive `*.tar.gz` for your target platform from [the releases page](https://github.com/hedhyw/gherkingen/releases/latest) and extract it to `/usr/local/bin/gherkingen`. Add this path to `PATH` environment.\n\nExample flow:\n```sh\n# Check the signature of a downloaded archive and the signature in the file task_checksums.txt from the release page.\n\n# Remove old binaries.\nrm -rf /usr/local/gherkingen\n# Restore folder structure.\nmkdir -p /usr/local/gherkingen\n# Extract archive to target path.\ntar -C /usr/local/gherkingen -xzf DOWNLOAD_ARCHIVE.TAR.GZ\n\n# Add `/usr/local/gherkingen` to PATH environment variable.\nexport PATH=/usr/local/gherkingen:$PATH\n# Check that the generator is working.\ngherkingen -help\n```\n\n## Go\n\n```bash\ngo install github.com/hedhyw/gherkingen/v4/cmd/gherkingen@latest\n# Notice: gherkingen -version will return \"unknown\" version.\n```\n\n## Source\n\n```\ngit clone git@github.com:hedhyw/gherkingen.git\ncd gherkingen\nmake build\ncp ./bin/gherkingen /usr/local/bin\nchmod +x /usr/local/bin\n```\n\n## Visual Studio Code extension\n\nThe extension for VS-Code that helps to generate Behaviour Driven Development (BDD) boilerplate Golang tests. It uses docker to run `gherkingen`.\n\nhttps://marketplace.visualstudio.com/items?itemName=hedhyw.golang-gherkingen\u0026ssr=false#overview\n\nLaunch VS Code Quick Open (Ctrl+P or Cmd+P), paste the following command, and press enter: `ext install hedhyw.golang-gherkingen`.\n\nUsage of the extension (in any .feature file):\n- Open the command palette (Ctrl+Shift+P or Cmd+Shift+P) and search for \"Go: Generate BDD Golang test\".\n- Or, click the button \"Generate BDD Golang test\" in the editor's menu.\n\n# Usage\n## Simple usage\n\nFor generating test output, simply run:\n\n```\ngherkingen EXAMPLE.feature\n```\n\n## More advanced usage\n\n### Generating test output with custom options\n```\ngherkingen \\\n    -format go \\\n    -template my_template.tmpl \\\n    EXAMPLE.feature\n```\n### Listing internal templates\n```\ngherkingen -list\n```\n\n### Help\n```\ngherkingen --help\n\nUsage of gherkingen [FEATURE_FILE]:\n  -disable-go-parallel\n        disable execution of tests in parallel\n  -format string\n        output format: autodetect, json, go, raw (default \"autodetect\")\n  -go-parallel\n        add parallel mark (deprecated, enabled by default) (default true)\n  -help\n        print usage\n  -language string\n        Specifies the natural language used to describe the feature.\n        This flag is optional if language information is included in the feature file name, or if the feature is written in English.\n        The file name should be formatted as follows: \u003cdescription\u003e.\u003clanguage_hint\u003e.feature if language hint is included, or \u003cdescription\u003e.feature if it is not.\n        When provided, the 'language' flag takes precedence over the language hint from the file name. (default \"en\")\n  -languages\n        list supported natural feature languages\n  -list\n        list internal templates\n  -package string\n        name of the generated package (default \"generated_test\")\n  -permanent-ids\n        The same calls to the generator always produces the same output\n  -template string\n        template file (default \"@/std.simple.v1.go.tmpl\")\n  -version\n        print version\n```\n\n## Running in docker\n\nDocker image: https://hub.docker.com/r/hedhyw/gherkingen\n\nRunning gherkingen in docker, `\u003cRELATIVE_PATH_TO_FEATURE_FILE\u003e` is\na path to a feature file relatively to the current directory.\n```sh\ndocker run --rm -it --read-only --network none \\\n\t--volume $PWD:/host/:ro \\\n\thedhyw/gherkingen:latest \\\n\t-- /host/\u003cRELATIVE_PATH_TO_FEATURE_FILE\u003e\n```\n\nPassing arguments:\n```sh\n# Any command-line tool arguments also can be used.\n# Example:\ndocker run --rm -it --read-only --network none \\\n\thedhyw/gherkingen:latest -list\n```\n\n# Output customization\n\n## Custom templates\nYou can provide your own template, it can be based on [internal/assets/std.simple.v1.go.tmpl](internal/assets/std.simple.v1.go.tmpl). In the command-line tool specify the template\nusing `-template` flag: `gherkingen -template example.tmpl raw example.feature`\n\n## Frameworks support\nIt is possible to integrate the generator with any BDD-testing fraemwork. Feel free to\ncreate a pull request for supporting templates for them. For this:\n1. Create a template `internal/assets/SOME_NAME.go.tmpl`.\n2. Add it to the test `TestOpenTemplate` in the file [internal/assets/assets_test.go](internal/assets/assets_test.go).\n3. Check: `make lint check.generate test`.\n4. Commit\u0026Push, create a PR.\n\n## Programming language support\n\nTemplates are very customizable, so you can even generate non-golang code. In the command-line tool specify `raw` format using `-format` flag and your template using `-template` flag:\n`gherkingen -format raw -template example.tmpl example.feature`.\n\n## Creating templates\n\nUseful resources:\n| Resource                                  | Link                                                 |\n|-------------------------------------------|------------------------------------------------------|\n| Golang template documentation             | [text/template](https://pkg.go.dev/text/template)    |\n| Root template object struct documentation | [TemplateData](https://pkg.go.dev/github.com/hedhyw/gherkingen/internal/model#TemplateData) |\n| Example template                          | [std.simple.v1.go.tmpl](./internal/assets/std.simple.v1.go.tmpl) |\n| Example json representation of a root template object | [readme.feature.json](internal/generator/examples/readme.feature.json)     |\n\nThere is a way to return a json representation of the root object `TemplateData` for your feature, for this run `gherkingen -format json \u003cEXAMPLE.feature\u003e`.\n\nAny field of the root object can be used directly, example: `{{ .PackageName }}`.\n\n## golangci-lint `thelper` warning\n\nExclude the rule `thelper` for scenarios in the configuration **.golangci.yaml**:\n\n```yaml\nissues:\n  fix: true\n  exclude-rules:\n    - linters:\n        - thelper\n      source: \"^.*f\\\\.Scenario.*$\"\n```\n\n# License\n\n- The library and generator are under [MIT Lecense](LICENSE).\n- [The gopher](./assets/gopher.png) is under [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/) license. It was originally designed by [Renée French](https://en.wikipedia.org/wiki/Ren%C3%A9e_French) and redrawed by me.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedhyw%2Fgherkingen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedhyw%2Fgherkingen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedhyw%2Fgherkingen/lists"}