Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何处理多个问题;然后";步骤定义?_Java_Cucumber_Gherkin_Citrus Framework - Fatal编程技术网

Java 如何处理多个问题;然后";步骤定义?

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

考虑一个具有多个“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" 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");
    }
}