Get support for go-bdd/gobdd

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

go-bdd/gobdd

GOBDD

GoDoc Coverage Status

This is a BDD testing framework. Uses gherkin for the test's syntax. From version 1.0, the API is stable.

Why did I make the library?

There is godog library for BDD tests in Go. I found this library useful but it runs as an external application which compiles our code. It has several disadvantages:

  • no debugging (breakpoints) in the test. Sometimes it’s useful to go through the whole execution step by step
  • metrics don’t count the test run this way
  • some style checkers recognise tests as dead code
  • it’s impossible to use built-in features like build constraints.
  • no context in steps - so the state have to be stored somewhere else - in my opinion, it makes the maintenance harder

Quick start

Add the package to your project:

go get github.com/go-bdd/gobdd

Inside features folder create your scenarios. Here is an example:

Feature: math operations
  Scenario: add two digits
    When I add 1 and 2
    Then the result should equal 3

Add a new test main_test.go:

func add(t gobdd.StepTest, ctx gobdd.Context, var1, var2 int) {
	res := var1 + var2
	ctx.Set("sumRes", res)
}

func check(t gobdd.StepTest, ctx gobdd.Context, sum int) {
	received, err := ctx.GetInt("sumRes")
	if err != nil {
		t.Error(err)
		return
	}

	if sum != received {
		t.Error(errors.New("the math does not work for you"))
	}
}

func TestScenarios(t *testing.T) {
	suite := gobdd.NewSuite(t)
	suite.AddStep(`I add (\d+) and (\d+)`, add)
	suite.AddStep(`the result should equal (\d+)`, check)
	suite.Run()
}

and run tests

go test ./...

More detailed documentation can be found on the docs page: https://go-bdd.github.io/gobdd/. A sample application is available in a separate repository.

Contributing

All contributions are very much welcome. If you'd like to help with GoBDD development, please see open issues and submit your pull request via GitHub.

Support

If you didn't find the answer to your question in the documentation, feel free to ask us directly!

Please join us on the #gobdd-library channel on the Gophers slack: You can get an invite here. You can find updates about the progress on Twitter: GoBdd.

You can support my work using issuehunt or by buying me a coffee.

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2