GithubHelp home page GithubHelp logo

connextrum / gobdd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from go-bdd/gobdd

0.0 0.0 0.0 201 KB

BDD framework

Home Page: https://go-bdd.github.io/gobdd/

License: MIT License

Go 88.91% Gherkin 11.09%

gobdd's Introduction

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.

gobdd's People

Contributors

bkielbasa avatar sagikazarmark avatar jirikuncar avatar vlalanne avatar arberiii avatar ristomcgehee avatar zippolyte avatar mirogta avatar sblundy avatar svandecappelle avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.