**这样的实现可以在空手道中完成(这在我本地不起作用)?: ** public class CreateRetrieveUpdateDelete { StepDefs stepDefs = new StepDefs();
@When("^Create using service ([^\\\"]*)$")
public void whenCreate(String service, String payload) {
stepDefs.url(service);
stepDefs.request(payload);
stepDefs.method("post");
stepDefs.matchContains("", "", "", "", "", "");
stepDefs.status(201);
}
@When("^Retrieve using service ([^\\\"]*)$")
public void whenRetrieve(String service) {
stepDefs.url(service);
stepDefs.method("get");
stepDefs.matchContains("", "", "", "", "", "");
stepDefs.status(200);
}
@When("^Update using service ([^\\\"]*)$")
public void whenUpdate(String service, String payload) {
stepDefs.url(service);
stepDefs.request(payload);
stepDefs.method("put");
stepDefs.matchContains("", "", "", "", "", "");
stepDefs.status(201);
}
@When("^Delete using service ([^\\\"]*)$")
public void whenDelete(String service) {
stepDefs.url(service);
stepDefs.method("delete");
stepDefs.status(204);
}
}
答案 0 :(得分:0)
空手道不适合与黄瓜混合使用。
请参阅此Stack Overflow回答:https://stackoverflow.com/a/46229979/143475
答案 1 :(得分:-1)
最后有些工作就像复合步骤一样,在使用空手道时减少了功能文件中的大量样板步骤,我在StepDefs.java中添加了这个方法,做了mvn clean install,然后在.feature中添加了一个Scenario,我们可以拥有这样的复合步骤很容易融入空手道?
@When("I Retrieve using service (.+)$")
public void whenRetrieve(String service) {
request.setUrl("http://localhost:3000/" + service);
method("get");
String responseBody = response.toString();
System.out.println(responseBody);
status(200);
}
Feature:
CRUD demo
Background:
Demo CRUD
Scenario: Retrieve
When I Retrieve using service posts/1/