Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/testing/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
存在步骤时,Godog未定义步骤_Go_Testing_Visual Studio Code_Cucumber_Bdd - Fatal编程技术网

存在步骤时,Godog未定义步骤

存在步骤时,Godog未定义步骤,go,testing,visual-studio-code,cucumber,bdd,Go,Testing,Visual Studio Code,Cucumber,Bdd,我一直在使用Godog为Golang的一个微服务实现功能文件测试 在我的功能文件中有54个步骤,我为它们生成了步骤定义 当我使用go test命令运行测试时,前22个场景通过,23个场景被声明为Undefined,即使它的定义存在 任何测试后,我的控制台输出: ......................U------------------------U-----U 54 1 scenarios (1 undefined) 54 steps (22 passed, 3 undefined,

我一直在使用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\u 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)
}

有谁能指出这背后的问题是什么,或者这是一个bug吗?

结果是Godog没有从
功能文件中删除步骤

因此,在我的功能文件中,上述行的步骤包括:

读取id为“ID1”的资源时(空白)

因此,由于某种原因,regex模式无法将步骤定义映射到这些行

我一把空的地方移走,效果就很好