存在步骤时 Godog 未定义步骤
Godog Undefined Steps when Steps are present
我一直在使用 Godog 在 Golang 中为微服务实施功能文件测试。
我的功能文件中有 54 个步骤,我为所有步骤生成了步骤定义。
当我 运行 使用 go test
命令进行测试时,前 22 个场景通过并且 23 被声明为 Undefined
,即使它的定义存在。
任何测试后我的控制台输出:
......................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
这是我的 main_test.go
文件中的片段
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)
}
任何人都可以指出这背后的问题是什么,还是一个错误?
事实证明 Godog 没有 trim feature
文件中的步骤。
因此,在我的功能文件中,上述几行的步骤包括:
读取id为“ID1”的资源时_____(空白space)
因此正则表达式模式由于某种原因无法将步骤定义映射到这些行。
我一删除空的 spaces,效果很好。
我一直在使用 Godog 在 Golang 中为微服务实施功能文件测试。
我的功能文件中有 54 个步骤,我为所有步骤生成了步骤定义。
当我 运行 使用 go test
命令进行测试时,前 22 个场景通过并且 23 被声明为 Undefined
,即使它的定义存在。
任何测试后我的控制台输出:
......................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
这是我的 main_test.go
文件中的片段
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)
}
任何人都可以指出这背后的问题是什么,还是一个错误?
事实证明 Godog 没有 trim feature
文件中的步骤。
因此,在我的功能文件中,上述几行的步骤包括:
读取id为“ID1”的资源时_____(空白space)
因此正则表达式模式由于某种原因无法将步骤定义映射到这些行。
我一删除空的 spaces,效果很好。