Skip to content

Commit

Permalink
example to run godog from go test, closes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
l3pp4rd committed Jul 11, 2016
1 parent 12144ef commit 409db5f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,49 @@ Now when you run the `godog` again, you should see:
more events, like **AfterStep** to test against an error and print more details about the error
or state before failure. Or **BeforeSuite** to prepare a database.

#### Running Godog with go test

There was a question asked whether it is possible to run **godog** from
**go test** command. And the answer is yes. 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 example:

``` go
/* file: $GOPATH/src/godogs/godogs_test.go */
package main

import (
"flag"
"os"
"testing"

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

func TestMain(m *testing.M) {
args := os.Args
// args for godog
os.Args = []string{
args[0],
"-f", "progress",
"features",
}

status := godog.Run(func(s *godog.Suite) {
FeatureContext(s)
})

os.Args = args
flag.Parse()

if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
```

### References and Tutorials

- [how to use godog by semaphoreci](https://semaphoreci.com/community/tutorials/how-to-use-godog-for-behavior-driven-development-in-go)
Expand Down
25 changes: 25 additions & 0 deletions examples/godogs/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@
package main

import (
"flag"
"fmt"
"os"
"testing"

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

func TestMain(m *testing.M) {
args := os.Args
// args for godog
os.Args = []string{
args[0],
"-f", "progress",
"features",
}

status := godog.Run(func(s *godog.Suite) {
FeatureContext(s)
})

os.Args = args
flag.Parse()

if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}

func thereAreGodogs(available int) error {
Godogs = available
return nil
Expand Down

0 comments on commit 409db5f

Please sign in to comment.