Popularity
2.7
Growing
Activity
7.9
Growing
49
2
1

Programming language: Go
License: MIT License
Tags: Testing     Testing Frameworks    

gherkingen alternatives and similar packages

Based on the "Testing Frameworks" category.
Alternatively, view gherkingen alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of gherkingen or a related project?

Add another 'Testing Frameworks' Package

README

gherkingen

Version Build Status Go Report Card Coverage Status

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

It accepts a *.feature Cucumber/Gherkin 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.

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](readme.feature.example) [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](readme.go.example) 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 `field:"<flag>"`
        }

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

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

            f.TestCase(name, tc, func(t *testing.T, f *bdd.Feature) {
                f.When("<flag> is provided", func() {

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

                })
            })
        }
    })
}

Then on failure next logs will be printed:

Feature: Application command line tool
    Scenario: User wants to see usage information
        # TestCase: {Flag:-help}
        When: -help is provided
        Then: usage should be printed

More advanced example

See [internal/app/app.feature](internal/app/app.feature) and [internal/app/app_test.go](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.v1.go.tmpl")

Output customization

Custom templates

You can provide your own template, it can be based on [internal/assets/std.args.v1.go.tmpl](internal/assets/std.args.v1.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](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](License).


*Note that all licence references and agreements mentioned in the gherkingen README section above are relevant to that project's source code only.