Godog 在步骤之间传递参数/状态

标签 go concurrency cucumber gherkin

为了满足并发要求,我想知道如何在 Godog 中的多个步骤之间传递参数或状态。

func FeatureContext(s *godog.Suite) {
    // This step is called in background
    s.Step(`^I work with "([^"]*)" entities`, iWorkWithEntities)
    // This step should know about the type of entity
    s.Step(`^I run the "([^"]*)" mutation with the arguments:$`, iRunTheMutationWithTheArguments)

我想到的唯一想法是内联被调用的函数:

state := make(map[string]string, 0)
s.Step(`^I work with "([^"]*)" entities`, func(entityName string) error {
    return iWorkWithEntities(entityName, state)
})
s.Step(`^I run the "([^"]*)" mutation with the arguments:$`, func(mutationName string, args *messages.PickleStepArgument_PickleTable) error {
    return iRunTheMutationWithTheArguments(mutationName, args, state)
})

但这感觉有点像解决方法。 Godog 库本身有什么功能可以传递这些信息吗?

最佳答案

我在步骤中使用方法而不是函数找到了好运。然后,将状态放入结构中。

func FeatureContext(s *godog.Suite) {
    t := NewTestRunner()

    s.Step(`^I work with "([^"]*)" entities`, t.iWorkWithEntities)
}

type TestRunner struct {
    State map[string]interface{}
}

func (t *TestRunner) iWorkWithEntities(s string) error {
    t.State["entities"] = s
    ...
}

关于Godog 在步骤之间传递参数/状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60948850/

相关文章:

JSON 在 go 中将相同的结构编码/解码为不同的 JSON 格式?

MongoDB 与 golang 错误 "no reachable servers"

java - 从另一个主要方法使用 Main.run 运行 Cucumber 项目

eclipse - 如何在eclipse IDE中执行go test文件

java - java中的bug线程处理

concurrency - 同一多处理器上的并发、唯一内核?

java - 解决Java中链表的手动锁定死锁问题

java - Cucumber:许多示例行 VS 许多场景轮廓

ios - 弗兰克设置给出错误,

golang 是否有一种简单的方法来解码任意复杂的 json