黄瓜在 Java 中拆分 JSON 字符串错误
Cucumber splits JSON string wrong in 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字符串不应该被拆分。
我没有把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 消息,而不是直接在步骤正则表达式中拆分。
当我在 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字符串不应该被拆分。
我没有把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 消息,而不是直接在步骤正则表达式中拆分。