Java 如何处理多个问题;然后";步骤定义?
考虑一个具有多个“Then”步骤定义的场景,这些定义将用作针对响应负载的断言:Java 如何处理多个问题;然后";步骤定义?,java,cucumber,gherkin,citrus-framework,Java,Cucumber,Gherkin,Citrus Framework,考虑一个具有多个“Then”步骤定义的场景,这些定义将用作针对响应负载的断言: ... When a response is received Then the response should have an element "foo" with the content "bar" And the response should contain 1 "foobar" element And the response should have an element "rab" w
...
When a response is received
Then the response should have an element "foo" with the content "bar"
And the response should contain 1 "foobar" element
And the response should have an element "rab" with the content "oof"
...
Citrus处理未知数量验证的预期方式是什么?在调用receive()
之前,能否定义几个验证器?这可以通过validationCallback()
和最小的小黄瓜重写来处理吗
当前实现使用
validationCallback()
将负载存储为实例变量,然后根据变量进行验证。不过,最好利用Citrus的强大功能。您可以在给定的部分甚至场景背景中使用命名消息:
Given message fooResponse
And <fooResponse> payload is "Hi my name is Foo!"
And <fooResponse> header operation is "sayHello"
...
如果需要处理大型XML/Json有效负载,还可以从外部文件模板资源加载该有效负载。与在单独的显式语句中设置每个元素不同,您应该使用基于模板的比较验证,该验证还可以使用@ignore@
部分忽略与验证无关的消息部分。使用XML模板是我们最终要做的,而不是使用n
数量然后
/和
s。
Scenario: Send and receive
When <client> sends message <fooRequest>
Then <client> should receive message <fooResponse>
Background:
Given message creator com.consol.citrus.FooMessageCreator
public class FooMessageCreator {
@MessageCreator("fooResponse")
public Message createEchoResponse() {
return new DefaultMessage("Hi my name is Foo!")
.setHeader("operation", "sayHello");
}
}