黄瓜在Java中错误地分割JSON字符串

时间:2016-05-18 17:45:45

标签: cucumber cucumber-java

当我在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字符串。

1 个答案:

答案 0 :(得分:0)

我不会将json直接放入步骤定义中,因为我觉得它太乱了。试试these examples

  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消息拆分,而不是直接在步骤regexp中。