英文:
Godog Undefined Steps when Steps are present
问题
我一直在使用Godog在Golang中为一个微服务实现功能文件测试。
我的功能文件中有54个步骤,我为所有这些步骤生成了步骤定义。
当我使用go test
命令运行测试时,前22个场景通过了,第23个场景被声明为Undefined
,尽管它的定义是存在的。
我的控制台输出如下:
......................U------------------------U-----U 54
1个场景(1个未定义)
54个步骤(22个通过,3个未定义,29个跳过)
44.0003毫秒
随机种子:1621922954984294500
您可以使用以下代码片段实现未定义步骤的步骤定义:
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: 警告:没有要运行的测试
PASS
ok gitlab.com/xxxxxx/go-micro-service 0.595秒
这是我的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)
}
有人能指出这个问题是什么,或者这是一个错误吗?
英文:
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?
答案1
得分: 1
原文翻译如下:
原来Godog不会修剪feature
文件中的步骤。
因此,在我的feature文件中,上述行的步骤包括:
当读取id为"ID1"的资源_____(空格)
由于正则表达式模式无法将步骤定义映射到这些行,所以出现了问题。
一旦我移除了空格,它就正常工作了。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论