package
0.0.0-20241119031517-d78a05f52a91
Repository: https://github.com/muly/golang.git
Documentation: pkg.go.dev

# README

steps to get ready with implementing cocumber using golang godog library

1. install godog

go get github.com/cucumber/godog/cmd/godog

or, to install a specific version instead of master

go get github.com/cucumber/godog/cmd/[email protected]

2. define features

see features/google.feature file

3. generate the golang snippets

From the project folder where the features folder exists, run the below command to genetrate golang code snippet for all the features

godog

to generate the code snippet for a single feature, provide the relative path of the corresponding feature file

godog features/google.feature

generated code snippet looks as below:

func iSentRequestTo(arg1, arg2 string) error {
        return godog.ErrPending
}

func theResponseCodeShouldBe(arg1 int) error {
        return godog.ErrPending
}

func InitializeScenario(ctx *godog.ScenarioContext) {
        ctx.Step(`^I sent "([^"]*)" request to "([^"]*)"$`, iSentRequestTo)
        ctx.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
}

copy the generated code snippet and save to a _test.go file

3. implement feature functions in go

  • in the generated code snippets, implement the actual test code that tests the given feature.
  • modify all the code as necessary. see google_test.go

4. run the tests

From the project folder where the features folder exists, run the below command to test the all the features

godog

to test a single feature, provide the relative path of the corresponding feature file

godog features/google.feature

sample output:

s@mulys-new-mbp hello-cucumber % godog
Feature: get google query

  Scenario: should return google search results                           # features/google.feature:5
    When I sent "GET" request to "https://www.google.com/search?q=golang" # google_test.go:18 -> *apiFeature
    Then the response code should be 200                                  # google_test.go:33 -> *apiFeature

1 scenarios (1 passed)
2 steps (2 passed)
308.913146ms
s@mulys-new-mbp hello-cucumber % 

references:

inspired by the example: https://github.com/cucumber/godog/tree/main/_examples/api