0

当我在 Java 测试中使用 Cucumber 时,JSON 字符串作为输入似乎有问题,例如

Scenario Outline: not work
Given anythin
When I use <body> as body to call <url>
Then I'll get a status code of <status>

Examples:
| body    | url             | status        | 
| {"id":5}| /rest/update/0  | 404           | 

错误显示:

You can implement missing steps with the snippets below:

@When("^I use {\"([^\"]*)\":(\\d+)} as body to call \"([^\"]*)\"$")
public void i_use_as_body_to_call(String arg1, int arg2, String arg3) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();

}

但实际上,整个 JSON 字符串不应该被拆分。

4

1 回答 1

0

我没有将json直接放入步骤定义中,因为我认为它太乱了。试试这些例子

  Given I have a web service
  And I have "PUT" service for "/test"
  And I am a rest client
  When I "PUT" to the web service with the following
    """
    {"Question": "What is the meaning of life?"}
    """
  Then I receive the expected message

我没有使用任何场景大纲,但我认为你可以做到。无论如何,这最终可能会导致阅读变得非常混乱。此外,我通常将所有场景大纲放在引号中以保持简洁。还有一件事,我在步骤定义中拆分了我的 json 消息,而不是直接在步骤正则表达式中。

于 2016-05-18T20:58:55.393 回答