Godog - приёмочные тесты по-человечески (форк https://github.com/cucumber/godog)
Найти файл
2015-06-29 14:10:39 +03:00
cmd/godog closes #1 2015-06-23 22:38:50 +03:00
example use reflection to set step arguments #9 2015-06-27 23:46:43 +03:00
features add pending step error and handling 2015-06-29 14:10:39 +03:00
screenshots add an example in readme 2015-06-23 16:38:33 +03:00
.gitignore add an ls feature example 2015-06-23 13:51:45 +03:00
.travis.yml minor optimizations, add []byte support for arguments 2015-06-28 11:37:05 +03:00
builder.go add an ls feature example 2015-06-23 13:51:45 +03:00
flags.go closes #5 2015-06-25 10:13:15 +03:00
fmt.go add pending step error and handling 2015-06-29 14:10:39 +03:00
fmt_pretty.go add pending step error and handling 2015-06-29 14:10:39 +03:00
fmt_progress.go add pending step error and handling 2015-06-29 14:10:39 +03:00
fmt_test.go add pending step error and handling 2015-06-29 14:10:39 +03:00
godog.go fix readme 2015-06-27 20:00:41 +03:00
LICENSE give a project name 2015-06-10 16:15:01 +03:00
Makefile refactor to use cocumber gherkin3 parser library 2015-06-25 21:19:02 +03:00
README.md minor optimizations, add []byte support for arguments 2015-06-28 11:37:05 +03:00
stepdef.go minor optimizations, add []byte support for arguments 2015-06-28 11:37:05 +03:00
suite.go add pending step error and handling 2015-06-29 14:10:39 +03:00
suite_test.go add pending step error and handling 2015-06-29 14:10:39 +03:00
tag_filter_test.go refactor to use cocumber gherkin3 parser library 2015-06-25 21:19:02 +03:00
utils.go add an ls feature example 2015-06-23 13:51:45 +03:00

Build Status GoDoc

Godog

Godog is an open source behavior-driven development framework for go programming language. What is behavior-driven development, you ask? Its the idea that you start by writing human-readable sentences that describe a feature of your application and how it should work, and only then implement this behavior in software.

The project is inspired by behat and cucumber and is based on cucumber gherkin3 parser.

Godog does not intervene with the standard go test command and it's behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in _test.go files.

Godog acts similar compared to go test command. It builds all package sources to a single main package file and replaces main func with it's own and runs the build to test described application behavior in feature files. Production builds remains clean without any overhead.

Install

go get github.com/DATA-DOG/godog/cmd/godog

Example

Imagine we have a godog cart to serve godogs for dinner. At first, we describe our feature in plain text:

# file: /tmp/godog/godog.feature
Feature: eat godogs
  In order to be happy
  As a hungry gopher
  I need to be able to eat godogs

  Scenario: Eat 5 out of 12
    Given there are 12 godogs
    When I eat 5
    Then there should be 7 remaining

As a developer, your work is done as soon as youve made the program behave as described in the Scenario.

If you run godog godog.feature inside the /tmp/godog directory. You should see that the steps are undefined:

Screenshot

NOTE: the undefined step templates are still in development and scheduled for 0.2.0

/* file: /tmp/godog/godog.go */
package main

type GodogCart struct {
	reserve int
}

func (c *GodogCart) Eat(num int) { c.reserve -= num }

func (c *GodogCart) Available() int { return c.reserve }

func main() { /* usual main func */ }

Now lets describe all steps to test the application behavior:

/* file: /tmp/godog/godog_test.go */
package main

import (
	"fmt"

	"github.com/DATA-DOG/godog"
)

func (c *GodogCart) resetReserve(interface{}) {
	c.reserve = 0
}

func (c *GodogCart) thereAreNumGodogsInReserve(avail int) error {
	c.reserve = avail
	return nil
}

func (c *GodogCart) iEatNum(num int) error {
	c.Eat(num)
	return nil
}

func (c *GodogCart) thereShouldBeNumRemaining(left int) error {
	if c.Available() != left {
		return fmt.Errorf("expected %d godogs to be remaining, but there is %d", left, c.Available())
	}
	return nil
}

func godogCartContext(s godog.Suite) {
	c := &GodogCart{}
	// each time before running scenario reset reserve
	s.BeforeScenario(c.resetReserve)
	// register steps
	s.Step(`^there are (\d+) godogs?$`, c.thereAreNumGodogsInReserve)
	s.Step(`^I eat (\d+)$`, c.iEatNum)
	s.Step(`^there should be (\d+) remaining$`, c.thereShouldBeNumRemaining)
}

Now when you run the godog godog.feature again, you should see:

Screenshot

Documentation

See godoc for general API details. See .travis.yml for supported go versions.

The public API is stable enough, but it may break until 1.0.0 version, see godog --version.

FAQ

Q: Where can I configure common options globally? A: You can't. Alias your common or project based commands: alias mygodog="godog --format=progress --tags=@wip"

Contributions

Feel free to open a pull request. Note, if you wish to contribute an extension to public (exported methods or types) - please open an issue before to discuss whether these changes can be accepted. All backward incompatible changes are and will be treated cautiously.

License

All package dependencies are MIT or BSD licensed.

Godog is licensed under the three clause BSD license