将带有双引号字符串的参数传递给步骤

Pass arguments with double quotes string to steps

我有以下 Scenario 定义:

Scenario: test
    When test starts
    Then check data with '{"age":"18","gender":"male"}'

然后尝试将{"age":"18","gender":"male"}传递给步骤:

func FeatureContext(s *godog.ScenarioContext) {
    s.Step(`^check data with "([^']*)"$`, checkDataWith)
}

func checkDataWith(data string) error {
    return godog.ErrPending
}

上面说step不是impelmented,貌似{"age":"18","gender":"male"}没有传递正确,如何把{"age":"18","gender":"male"}这样的参数传递给step?

这个答案在另一个案例中帮助了我:

对于你的情况,你可以尝试:

func FeatureContext(s *godog.ScenarioContext) {
    s.Step(`^check data with '(.*)'$`, checkDataWith)
}

func checkDataWith(data string) error {
    return godog.ErrPending
}

因此数据将按照步骤描述中的方式传递到您的场景:

{"age":"18","gender":"male"}