I've been implementing feature file tests for a microservice in Golang using Godog.
There are 54 steps in my feature file and I generated the step definitions for all of them.
When I run the test using go test
command, the first 22 scenarios pass and the 23 is declared as Undefined
even though its definition is present.
My Console output after any test:
......................U------------------------U-----U 54
1 scenarios (1 undefined)
54 steps (22 passed, 3 undefined, 29 skipped)
44.0003ms
Randomized with seed: 1621922954984294500
You can implement step definitions for undefined steps with these snippets:
func readingResourceOfId(arg1 string) error {
return godog.ErrPending
}
func resourceWithIdIsFound(arg1 string) error {
return godog.ErrPending
}
func resourceWithIdIsNotFound(arg1 string) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^reading resource of id "([^"]*)"$`, readingResourceOfId)
ctx.Step(`^resource with id "([^"]*)" is found$`, resourceWithIdIsFound)
ctx.Step(`^resource with id "([^"]*)" is not found$`, resourceWithIdIsNotFound)
}
testing: warning: no tests to run
PASS
ok gitlab.com/xxxxxx/go-micro-service 0.595s
Here are snippets from my main_test.go
file
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{
Set: make(map[string]interface{}),
}
ctx.Step(`^API response code is (\d+)$`, api.aPIResponseCodeIs)
ctx.Step(`^API response Location header is "([^"]*)" with "([^"]*)" autogenerated$`, api.aPIResponseLocationHeaderIsWithAutogenerated)
ctx.Step(`^creating a resource with name "([^"]*)" and type "([^"]*)"$`, api.creatingAResourceWithNameAndType)
ctx.Step(`^deleting the resource of id "([^"]*)"$`, api.deletingTheResourceOfId)
ctx.Step(`^external resource id (\d+) is "([^"]*)"$`, api.externalResourceIdIs)
ctx.Step(`^finally setting reference to external resource (\d+) on id "([^"]*)"$`, api.finallySettingReferenceToExternalResourceOnId)
ctx.Step(`^id is "([^"]*)"$`, api.idIs)
ctx.Step(`^modifying resource of id "([^"]*)" setting status to "([^"]*)"$`, api.modifyingResourceOfIdSettingStatusTo)
ctx.Step(`^name is "([^"]*)"$`, api.nameIs)
ctx.Step(`^searching for resource instances$`, api.searchingForResourceInstances)
ctx.Step(`^setting reference to external resource (\d+) on id "([^"]*)"$`, api.settingReferenceToExternalResourceOnId)
ctx.Step(`^status end date is null$`, api.statusEndDateIsNull)
ctx.Step(`^status is "([^"]*)"$`, api.statusIs)
ctx.Step(`^status "([^"]*)" is found in history$`, api.statusIsFoundInHistory)
ctx.Step(`^status start date is not null$`, api.statusStartDateIsNotNull)
ctx.Step(`^the micro-service is started$`, api.theMicroserviceIsStarted)
ctx.Step(`^type is "([^"]*)"$`, api.typeIs)
//Steps are defined
ctx.Step(`^reading resource of id "([^"]*)"$`, api.readingResourceOfId)
ctx.Step(`^resource with id "([^"]*)" is found$`, api.resourceWithIdIsFound)
ctx.Step(`^resource with id "([^"]*)" is not found$`, api.resourceWithIdIsNotFound)
}
Can anyone point out what is the issue behind this, or is it a bug?
It turns out Godog doesn't trim the Steps from the feature
files.
So, In my feature files, the steps for the above lines included:
When reading resource of id "ID1"_____(blank space)
The regex pattern therefore wasn't able to map the step definitions to these lines for some reason.
As soon as I removed the empty spaces, it worked great.