Merge pull request #302 from cucumber/updated-readme

Updated the README.md
Этот коммит содержится в:
Fredrik Lönnblad 2020-06-10 21:44:44 +02:00 коммит произвёл GitHub
родитель 12a387ec46 0bd3a0e729
коммит f50bd30ec0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23

202
README.md
Просмотреть файл

@ -8,39 +8,38 @@
**The API is likely to change a few times before we reach 1.0.0** **The API is likely to change a few times before we reach 1.0.0**
Please read all the README, you may find it very useful. And do not forget Please read all the README, you may find it very useful. And do not forget to peek into the [CHANGELOG](https://github.com/cucumber/godog/blob/master/CHANGELOG.md) from time to time.
to peek into the
[CHANGELOG](https://github.com/cucumber/godog/blob/master/CHANGELOG.md)
from time to time.
Package godog is the official Cucumber BDD framework for Golang, it merges Package godog is the official Cucumber BDD framework for Golang, it merges specification and test documentation into one cohesive whole, using Gherkin formatted scenarios in the format of Given, When, Then.
specification and test documentation into one cohesive whole. The author
is a member of [cucumber team](https://github.com/cucumber).
The project is inspired by [behat][behat] and [cucumber][cucumber] and is **Godog** does not intervene with the standard **go test** command behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in **_test.go** files.
based on cucumber [gherkin3 parser][gherkin].
**Godog** does not intervene with the standard **go test** command **Godog** acts similar compared to **go test** command, by using go compiler and linker tool in order to produce test executable. Godog contexts need to be exported the same way as **Test** functions for go tests. Note, that if you use **godog** command tool, it will use `go` executable to determine compiler and linker.
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, by using go The project was inspired by [behat][behat] and [cucumber][cucumber].
compiler and linker tool in order to produce test executable. Godog
contexts need to be exported the same way as **Test** functions for go
tests. Note, that if you use **godog** command tool, it will use `go`
executable to determine compiler and linker.
**Godog** depends on [gherkin-go](https://github.com/cucumber/gherkin-go) and [messages-go](https://github.com/cucumber/messages-go). ## Why Godog/Cucumber
The following about section was taken from ### A single source of truth
[cucumber](https://cucumber.io/) homepage.
## Notice: Godog merges specification and test documentation into one cohesive whole.
**If your project depend on the master version of godog instead of a specific release, please read this.** ### Living documentation
Due to dependency changes in a coming merge to master, including breaking changes, you should update how you install or depend on godog so that you have a version specified. Because they're automatically tested by Godog, your specifications are
always bang up-to-date.
### Focus on the customer
Business and IT don't always understand each other. Godog's executable specifications encourage closer collaboration, helping teams keep the business goal in mind at all times.
### Less rework
When automated testing is this much fun, teams can easily protect themselves from costly regressions.
### Read more
- [Behaviour-Driven Development](https://cucumber.io/docs/bdd/)
- [Gherkin Reference](https://cucumber.io/docs/gherkin/reference/)
## Install ## Install
``` ```
@ -53,27 +52,21 @@ Running `within the $GOPATH`, you would also need to set `GO111MODULE=on`, like
GO111MODULE=on go get github.com/cucumber/godog/cmd/godog@v0.9.0 GO111MODULE=on go get github.com/cucumber/godog/cmd/godog@v0.9.0
``` ```
## About ## Contributions
#### A single source of truth Godog is a community driven Open Source Project within the Cucumber organization, it is maintained by a handfull of developers, but we appreciate contributions from everyone.
Cucumber merges specification and test documentation into one cohesive whole. If you are interested in developing Godog, we suggest you to visit one of our slack channels.
#### Living documentation Feel free to open a pull request. Note, if you wish to contribute larger changes or an extension to the exported methods or types, please open an issue before and visit us in slack to discuss the changes.
Because they're automatically tested by Cucumber, your specifications are Reach out to the community on our [Cucumber Slack Community](https://cucumberbdd.slack.com/).
always bang up-to-date. Join [here](https://cucumberbdd-slack-invite.herokuapp.com/).
#### Focus on the customer ### Popular Cucumber Slack channels for Godog:
- [#help-godog](https://cucumberbdd.slack.com/archives/CTNL1JCVA) - General Godog Adoption Help
Business and IT don't always understand each other. Cucumber's executable - [#committers-go](https://cucumberbdd.slack.com/archives/CA5NJPDJ4) - Golang focused Cucumber Contributors
specifications encourage closer collaboration, helping teams keep the - [#committers](https://cucumberbdd.slack.com/archives/C62D0FK0E) - General Cucumber Contributors
business goal in mind at all times.
#### Less rework
When automated testing is this much fun, teams can easily protect
themselves from costly regressions.
## Example ## Example
@ -81,12 +74,9 @@ The following example can be [found here](/_examples/godogs).
### Step 1 ### Step 1
Given we create a new go package **$GOPATH/src/godogs**. From now on, this Given we create a new go package **$GOPATH/src/godogs**. From now on, this is our work directory `cd $GOPATH/src/godogs`.
is our work directory `cd $GOPATH/src/godogs`.
Imagine we have a **godog cart** to serve godogs for lunch. First of all, Imagine we have a **godog cart** to serve godogs for lunch. First of all, we describe our feature in plain text - `vim $GOPATH/src/godogs/features/godogs.feature`:
we describe our feature in plain text - `vim
$GOPATH/src/godogs/features/godogs.feature`:
``` gherkin ``` gherkin
# file: $GOPATH/src/godogs/features/godogs.feature # file: $GOPATH/src/godogs/features/godogs.feature
@ -101,37 +91,29 @@ Feature: eat godogs
Then there should be 7 remaining Then there should be 7 remaining
``` ```
**NOTE:** same as **go test** godog respects package level isolation. All **NOTE:** same as **go test** godog respects package level isolation. All your step definitions should be in your tested package root directory. In this case - `$GOPATH/src/godogs`
your step definitions should be in your tested package root directory. In
this case - `$GOPATH/src/godogs`
### Step 2 ### Step 2
If godog is installed in your GOPATH. We can run `godog` inside the If godog is installed in your GOPATH. We can run `godog` inside the **$GOPATH/src/godogs** directory. You should see that the steps are undefined:
**$GOPATH/src/godogs** directory. You should see that the steps are
undefined:
![Undefined step snippets](/screenshots/undefined.png?raw=true) ![Undefined step snippets](/screenshots/undefined.png?raw=true)
If we wish to vendor godog dependency, we can do it as usual, using tools If we wish to vendor godog dependency, we can do it as usual, using tools you prefer:
you prefer:
git clone https://github.com/cucumber/godog.git $GOPATH/src/godogs/vendor/github.com/cucumber/godog git clone https://github.com/cucumber/godog.git $GOPATH/src/godogs/vendor/github.com/cucumber/godog
It gives you undefined step snippets to implement in your test context. It gives you undefined step snippets to implement in your test context. You may copy these snippets into your `godogs_test.go` file.
You may copy these snippets into your `godogs_test.go` file.
Our directory structure should now look like: Our directory structure should now look like:
![Directory layout](/screenshots/dir-tree.png?raw=true) ![Directory layout](/screenshots/dir-tree.png?raw=true)
If you copy the snippets into our test file and run godog again. We should If you copy the snippets into our test file and run godog again. We should see the step definition is now pending:
see the step definition is now pending:
![Pending step definition](/screenshots/pending.png?raw=true) ![Pending step definition](/screenshots/pending.png?raw=true)
You may change **ErrPending** to **nil** and the scenario will You may change **ErrPending** to **nil** and the scenario will pass successfully.
pass successfully.
Since we need a working implementation, we may start by implementing only what is necessary. Since we need a working implementation, we may start by implementing only what is necessary.
@ -150,8 +132,7 @@ func main() { /* usual main func */ }
### Step 4 ### Step 4
Now lets implement our step definitions, which we can copy from generated Now lets implement our step definitions, which we can copy from generated console output snippets in order to test our feature requirements:
console output snippets in order to test our feature requirements:
``` go ``` go
package main package main
@ -217,36 +198,24 @@ Now when you run the `godog` again, you should see:
![Passed suite](/screenshots/passed.png?raw=true) ![Passed suite](/screenshots/passed.png?raw=true)
We have hooked to **BeforeScenario** event in order to reset application We have hooked to **BeforeScenario** event in order to reset application state before each scenario. You may hook into more events, like **AfterStep** to print all state in case of an error. Or **BeforeSuite** to prepare a database.
state before each scenario. You may hook into more events, like
**AfterStep** to print all state in case of an error. Or
**BeforeSuite** to prepare a database.
By now, you should have figured out, how to use **godog**. Another advice By now, you should have figured out, how to use **godog**. Another advice is to make steps orthogonal, small and simple to read for a user. Whether the user is a dumb website user or an API developer, who may understand a little more technical context - it should target that user.
is to make steps orthogonal, small and simple to read for a user. Whether
the user is a dumb website user or an API developer, who may understand
a little more technical context - it should target that user.
When steps are orthogonal and small, you can combine them just like you do When steps are orthogonal and small, you can combine them just like you do with Unix tools. Look how to simplify or remove ones, which can be composed.
with Unix tools. Look how to simplify or remove ones, which can be
composed.
### References and Tutorials ### References and Tutorials
- [cucumber-html-reporter](https://github.com/gkushang/cucumber-html-reporter) - [cucumber-html-reporter](https://github.com/gkushang/cucumber-html-reporter),
may be used in order to generate **html** reports together with may be used in order to generate **html** reports together with **cucumber** output formatter. See the [following docker image](https://github.com/myie/cucumber-html-reporter) for usage details.
**cucumber** output formatter. See the [following docker
image](https://github.com/myie/cucumber-html-reporter) for usage
details.
- [how to use godog by semaphoreci](https://semaphoreci.com/community/tutorials/how-to-use-godog-for-behavior-driven-development-in-go) - [how to use godog by semaphoreci](https://semaphoreci.com/community/tutorials/how-to-use-godog-for-behavior-driven-development-in-go)
- see [examples](https://github.com/cucumber/godog/tree/master/_examples) - see [examples](https://github.com/cucumber/godog/tree/master/_examples)
- see extension [AssistDog](https://github.com/hellomd/assistdog), which - see extension [AssistDog](https://github.com/hellomd/assistdog),
may have useful **gherkin.DataTable** transformations or comparison which may have useful **gherkin.DataTable** transformations or comparison methods for assertions.
methods for assertions.
### Documentation ### Documentation
See [godoc][godoc] for general API details. See [pkg documentation][godoc] for general API details.
See **[Circle Config](/.circleci/config.yml)** for supported **go** versions. See **[Circle Config](/.circleci/config.yml)** for supported **go** versions.
See `godog -h` for general command options. See `godog -h` for general command options.
@ -260,13 +229,9 @@ See implementation examples:
### Running Godog with go test ### Running Godog with go test
You may integrate running **godog** in your **go test** command. You can You may integrate running **godog** in your **go test** command. You can run it using go [TestMain](https://golang.org/pkg/testing/#hdr-Main) func available since **go 1.4**. In this case it is not necessary to have **godog** command installed. See the following examples.
run it using go [TestMain](https://golang.org/pkg/testing/#hdr-Main) func
available since **go 1.4**. In this case it is not necessary to have
**godog** command installed. See the following examples.
The following example binds **godog** flags with specified prefix `godog` The following example binds **godog** flags with specified prefix `godog` in order to prevent flag collisions.
in order to prevent flag collisions.
``` go ``` go
var opts = godog.Options{ var opts = godog.Options{
@ -302,16 +267,14 @@ func TestMain(m *testing.M) {
} }
``` ```
Then you may run tests with by specifying flags in order to filter Then you may run tests with by specifying flags in order to filter features.
features.
``` ```
go test -v --godog.random --godog.tags=wip go test -v --godog.random --godog.tags=wip
go test -v --godog.format=pretty --godog.random -race -coverprofile=coverage.txt -covermode=atomic go test -v --godog.format=pretty --godog.random -race -coverprofile=coverage.txt -covermode=atomic
``` ```
The following example does not bind godog flags, instead manually The following example does not bind godog flags, instead manually configuring needed options.
configuring needed options.
``` go ``` go
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -341,9 +304,7 @@ func TestMain(m *testing.M) {
} }
``` ```
You can even go one step further and reuse **go test** flags, like You can even go one step further and reuse **go test** flags, like **verbose** mode in order to switch godog **format**. See the following example:
**verbose** mode in order to switch godog **format**. See the following
example:
``` go ``` go
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -384,9 +345,7 @@ Now when running `go test -v` it will use **pretty** format.
### Tags ### Tags
If you want to filter scenarios by tags, you can use the If you want to filter scenarios by tags, you can use the `-t=<expression>` or `--tags=<expression>` where `<expression>` is one of the following:
`-t=<expression>` or `--tags=<expression>` where `<expression>`
is one of the following:
- `@wip` - run all scenarios with wip tag - `@wip` - run all scenarios with wip tag
- `~@wip` - exclude all scenarios with wip tag - `~@wip` - exclude all scenarios with wip tag
@ -427,62 +386,29 @@ func (a *asserter) Errorf(format string, args ...interface{}) {
### Configure common options for godog CLI ### Configure common options for godog CLI
There are no global options or configuration files. Alias your common or There are no global options or configuration files. Alias your common or project based commands: `alias godog-wip="godog --format=progress --tags=@wip"`
project based commands: `alias godog-wip="godog --format=progress
--tags=@wip"`
### Testing browser interactions ### Testing browser interactions
**godog** does not come with builtin packages to connect to the browser. **godog** does not come with builtin packages to connect to the browser. You may want to look at [selenium](http://www.seleniumhq.org/) and probably [phantomjs](http://phantomjs.org/). See also the following components:
You may want to look at [selenium](http://www.seleniumhq.org/) and
probably [phantomjs](http://phantomjs.org/). See also the following
components:
1. [browsersteps](https://github.com/llonchj/browsersteps) - provides 1. [browsersteps](https://github.com/llonchj/browsersteps) - provides basic context steps to start selenium and navigate browser content.
basic context steps to start selenium and navigate browser content.
2. You may wish to have [goquery](https://github.com/PuerkitoBio/goquery) 2. You may wish to have [goquery](https://github.com/PuerkitoBio/goquery)
in order to work with HTML responses like with JQuery. in order to work with HTML responses like with JQuery.
### Concurrency ### Concurrency
In order to support concurrency well, you should reset the state and In order to support concurrency well, you should reset the state and isolate each scenario. They should not share any state. It is suggested to run the suite concurrently in order to make sure there is no state corruption or race conditions in the application.
isolate each scenario. They should not share any state. It is suggested to
run the suite concurrently in order to make sure there is no state
corruption or race conditions in the application.
It is also useful to randomize the order of scenario execution, which you It is also useful to randomize the order of scenario execution, which you can now do with **--random** command option.
can now do with **--random** command option.
**NOTE:** if suite runs with concurrency option, it concurrently runs **NOTE:** if suite runs with concurrency option, it concurrently runs every feature, not scenario per different features. This will be updated in release v0.10.0 to run every scenario concurrently.
every feature, not scenario per different features. This gives
a flexibility to isolate state per feature. For example using
**BeforeFeature** hook, it is possible to spin up costly service and shut
it down only in **AfterFeature** hook and share the service between all
scenarios in that feature. It is not advisable though, because you are
risking having a state dependency.
## 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.
Reach out to the community on our [Cucumber Slack Community](https://cucumberbdd.slack.com/).
Join [here](https://cucumberbdd-slack-invite.herokuapp.com/).
### Popular Cucumber Slack channels for Godog:
- [#help-godog](https://cucumberbdd.slack.com/archives/CTNL1JCVA) - General Godog Adoption Help
- [#committers-go](https://cucumberbdd.slack.com/archives/CA5NJPDJ4) - Golang focused Cucumber Contributors
- [#committers](https://cucumberbdd.slack.com/archives/C62D0FK0E) - General Cucumber Contributors
## License ## License
- **Godog** is licensed under the [MIT][license] **Godog** and **Gherkin** are licensed under the [MIT][license] and developed as a part of the [cucumber project][cucumber]
- **Gherkin** is licensed under the [MIT][license] and developed as
a part of the [cucumber project][cucumber]
[godoc]: http://godoc.org/github.com/cucumber/godog "Documentation on godoc" [godoc]: https://pkg.go.dev/github.com/cucumber/godog "Documentation on godog"
[golang]: https://golang.org/ "GO programming language" [golang]: https://golang.org/ "GO programming language"
[behat]: http://docs.behat.org/ "Behavior driven development framework for PHP" [behat]: http://docs.behat.org/ "Behavior driven development framework for PHP"
[cucumber]: https://cucumber.io/ "Behavior driven development framework" [cucumber]: https://cucumber.io/ "Behavior driven development framework"
[gherkin]: https://github.com/cucumber/gherkin-go "Gherkin3 parser for GO"
[license]: https://en.wikipedia.org/wiki/MIT_License "The MIT license" [license]: https://en.wikipedia.org/wiki/MIT_License "The MIT license"