go - 存在步骤时的Godog未定义步骤
问题描述
我一直在使用 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 没有从feature
文件中删除 Steps。
因此,在我的功能文件中,上述行的步骤包括:
读取ID为“ID1”的资源时_____(空格)
因此,由于某种原因,正则表达式模式无法将步骤定义映射到这些行。
一旦我删除了空白空间,它就很好用。
推荐阅读
- c++ - 从互斥锁函数中按值返回成员
- angular - 按文本搜索并更新 Observable
角 7 - debugging - 如何通过管道将命令标准输出传递给 lldb 调试文件标准输入
- laravel - Laravel webpack 包括自定义 javascript
- reactjs - 使用 Apollo 重新获取会更新该查询的所有实例,即使使用不同的参数
- java - 发布到 Play 商店后不会自动提供 SYSTEM_ALERT_WINDOW 权限
- arrays - 将索引匹配公式转换为 VBA
- java - 字母数字列排序不正确
- python - 烧瓶中的Python参数验证类
- javascript - Redux 表单向导对象值验证