Behaviour Driven Development tests generator for Golang

Overview

gherkingen

Version Build Status Go Report Card Coverage Status

It's a Behaviour Driven Development (BDD) tests generator for Golang.

Golang logo

It accept a *.feature Cucumber/Gherkin file and generates a test boilerplate. All that remains is to change the tests a little.

The generator is very customizable, it is possible to customize an output for any golang testing framework or even for another language.

What is for?

Simple example

Given feature [reference]:

Feature: Application command line tool
  Scenario: User wants to see usage information
    When <flag> is provided
    Then usage should be printed
    Examples:
    | <flag> |
    | --help |
    | -help  |

Then this generator writes a golang output:

func TestApplicationCommandLineTool(t *testing.T) {
	f := bdd.NewFeature(t, "Application command line tool")

	f.Scenario("User wants to see usage information", func(t *testing.T, f *bdd.Feature) {
		type testCase struct {
			flag string
		}

		testCases := map[string]testCase{
			"--help": {"--help"},
			"-help":  {"-help"},
		}

		for name, tc := range testCases {
			name, tc := name, tc

			t.Run(name, func(t *testing.T) {
				t.Logf("TestCase: %+v", tc)
				f.When("<flag> is provided", func() {

				})
				f.Then("usage should be printed", func() {

				})
			})
		}
	})
}

More advanced example

See internal/app/app.feature and internal/app/app_test.go.

Install

Run:

go install github.com/hedhyw/gherkingen/cmd/[email protected]

Usage

Simple usage

For generating test output, simply run:

gherkingen EXAMPLE.feature

More advanced usage

Generating test output with custom options

gherkingen \
    -format go \
    -template my_template.tmpl \
    EXAMPLE.feature

Listing internal templates

gherkingen -list

Help

gherkingen --help

Usage of gherkingen [FEATURE_FILE]:
  -format string
        output format: json, go, raw (default "go")
  -help
        print usage
  -list
        list internal templates
  -template string
        template file (default "@/std.struct.go.tmpl")

Output customization

Custom templates

You can provide your own template, it can be based on internal/assets/std.args.go.tmpl. In the command-line tool specify the template using -template flag: gherkingen -template example.tmpl raw example.feature

Frameworks support

It is possible to integrate the generator with any BDD-testing fraemwork. Feel free to create a pull request for supporting templates for them. For this:

  1. Create a template internal/assets/SOME_NAME.go.tmpl.
  2. Add it to the test TestOpenTemplate in the file internal/assets/assets_test.go.
  3. Check: make lint test.
  4. Commit&Push, create a PR.

Language support

Templates 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: gherkingen -format raw -template example.tmpl example.feature.

License

See License.

You might also like...
Ruby on Rails like test fixtures for Go. Write tests against a real database

testfixtures Warning: this package will wipe the database data before loading the fixtures! It is supposed to be used on a test database. Please, doub

Automatically update your Go tests

autogold - automatically update your Go tests autogold makes go test -update automatically update your Go tests (golden files and Go values in e.g. fo

A simple `fs.FS` implementation to be used inside tests.

testfs A simple fs.FS which is contained in a test (using testing.TB's TempDir()) and with a few helper methods. PS: This lib only works on Go 1.16+.

A next-generation testing tool. Orion provides a powerful DSL to write and automate your acceptance tests

Orion is born to change the way we implement our acceptance tests. It takes advantage of HCL from Hashicorp t o provide a simple DSL to write the acceptance tests.

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code. It provides a variety of helper functions and patterns for common infrastructure testing tasks,

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.

GoConvey is awesome Go testing Welcome to GoConvey, a yummy Go testing tool for gophers. Works with go test. Use it in the terminal or browser accordi

gostub is a library to make stubbing in unit tests easy

gostub gostub is a library to make stubbing in unit tests easy. Getting started Import the following package: github.com/prashantv/gostub Click here t

Robust framework for running complex workload scenarios in isolation, using Go; for integration, e2e tests, benchmarks and more! 💪

e2e Go Module providing robust framework for running complex workload scenarios in isolation, using Go and Docker. For integration, e2e tests, benchma

gomonkey is a library to make monkey patching in unit tests easy

gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from Bouke, you can read this blogpost for an explanation on how it works.

Comments
  • Template object documentation

    Template object documentation

    Now the application can return JSON representation of template object if flag -format is set to json, but it will be nicer if the object will be documented.

    documentation good first issue 
    opened by hedhyw 1
  • JS support problem

    JS support problem

    This is a great library, I would like to use it in my projects. But I think it has a bug, it doesnt really support JS. It should also be able to generate code in JS with Jest or Mocha, maybe both, depending on given parameters. And publish it on npm, it's a lot easier to install libraries from there. Please fix it ASAP, thanks!

    enhancement 
    opened by waymes 1
  • Feat: initialisms #23

    Feat: initialisms #23

    Support initialisms: "ID", "HTTP", ...

    Closes #23

    Braking changes: Go templates: GoName -> PluginData.GoName, GoValue -> PluginData.GoValue, GoType -> PluginData.GoType.

    enhancement 
    opened by hedhyw 0
Releases(v2.3.0)
Owner
Maxim Krivchun
Maxim Krivchun
Learn Go with test-driven development

Learn Go with Tests Art by Denise Formats Gitbook EPUB or PDF Translations 中文 Português 日本語 한국어 Support me I am proud to offer this resource for free,

Chris James 18.4k Sep 23, 2022
Extremely flexible golang deep comparison, extends the go testing package and tests HTTP APIs

go-testdeep Extremely flexible golang deep comparison, extends the go testing package. Latest news Synopsis Description Installation Functions Availab

Maxime Soulé 316 Sep 17, 2022
Golang application focused on tests

Maceio Golang application that listens for webhook events coming from Github, runs tests previously defined in a configuration file and returns the ou

Leonardo Damasceno 5 Sep 8, 2021
S3 etag tests for golang

S3-etag-tests Quickstart Run docker-compose up. Execute tests in /test with $ go

null 0 Dec 16, 2021
Simple test driven approach in "GOLANG"

Testing in GOLANG Usage Only test go test -v Coverage go test -cover or go test -coverprofile=coverage.out go tool cover -html=coverage.out Benchmark

mahdi imani 0 Dec 5, 2021
A yaml data-driven testing format together with golang testing library

Specimen Yaml-based data-driven testing Specimen is a yaml data format for data-driven testing. This enforces separation between feature being tested

Design it, Run it 0 Jan 31, 2022
Package for comparing Go values in tests

Package for equality of Go values This package is intended to be a more powerful and safer alternative to reflect.DeepEqual for comparing whether two

Google 3.1k Sep 22, 2022
Record and replay your HTTP interactions for fast, deterministic and accurate tests

go-vcr go-vcr simplifies testing by recording your HTTP interactions and replaying them in future runs in order to provide fast, deterministic and acc

Marin Atanasov Nikolov 944 Sep 25, 2022
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.

GoConvey is awesome Go testing Welcome to GoConvey, a yummy Go testing tool for gophers. Works with go test. Use it in the terminal or browser accordi

SmartyStreets 7.4k Sep 23, 2022
Testing framework for Go. Allows writing self-documenting tests/specifications, and executes them concurrently and safely isolated. [UNMAINTAINED]

GoSpec GoSpec is a BDD-style testing framework for the Go programming language. It allows writing self-documenting tests/specs, and executes them in p

Esko Luontola 114 Sep 27, 2022