【问题标题】:Using fitnesse to test services based on xml over http使用 Fitnesse 测试基于 xml over http 的服务
【发布时间】:2016-07-02 03:34:44
【问题描述】:

我正在努力想出一个好的方法来使用 Fitnesse 为基于 xml over http 的服务编写自动化验收测试。这些服务具有复杂的请求和响应,其中包含未在服务之间共享的模式中的 xml 元素。我不想创建大量的 Fixture 代码来构建请求、编组/解组以及为每个服务执行 http 调用。

我研究了 RestFixture(https://github.com/smartrics/RestFixture),这似乎是一种很好的方法来限制测试此类服务的管道工作量。唯一的问题是以一种好的方式生成请求。对于“真正的”休息服务,这不是问题,但我的服务在请求正文中需要大量 xml。

我想以某种方式允许测试人员使用 Scenario 表构建他们的请求,但是由于所有服务都使用不同的模式,所以如果不创建一个非常复杂的后备夹具来负责创建,我就无法做到这一点所有不同的请求或多个 Fixture,每个 Fixture 负责为一项服务生成请求。无论哪种情况,我都会重新编写昂贵的管道。 这里有没有人对此有一些想法?

【问题讨论】:

  • 我问了一个类似的问题,答案似乎是没有任何通用夹具。您需要编写自定义装置来处理将 XML 解析为 Fitnesse 支持的平面名称/值对的验证。决定如何公开解析的对象有点挑战性。
  • 好的,谢谢。我想我应该开始考虑一种公开解析对象的好方法。

标签: java testing automated-tests fitnesse fit-framework


【解决方案1】:

我创建了一个夹具来解决这个问题,而无需任何额外的编码:XmlHttpTest。使用模仿 XML 结构的(自定义)Java 代码不处理创建请求。相反,它被处理为生成需要替换占位符的文本值。使用 XPath 表达式执行检查。

单个调用的示例用法(摘自one of the project's GitHub wiki pages):

!define POST_BODY { {{{
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
  <s11:Body>
    <ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/">
      <ns1:ZIP>90210</ns1:ZIP>
    </ns1:GetCityWeatherByZIP>
  </s11:Body>
</s11:Envelope>
}}} }

|script         |xml http test                                                       |
|post           |${POST_BODY}   |to                   |${URL}                        |
|check          |response status|200                                                 |
|show           |response                                                            |
|register prefix|weather        |for namespace        |http://ws.cdyne.com/WeatherWS/|
|check          |xPath          |//weather:City/text()|Beverly Hills                 |

(Result)

或者(使用场景进行多次调用)

!*> Scenario definition
!define POST_BODY_2 { {{{
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
  <s11:Body>
    <ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/">
      <ns1:ZIP>@{zip}</ns1:ZIP>
    </ns1:GetCityWeatherByZIP>
  </s11:Body>
</s11:Envelope>
}}} }

|script|xml http test|

|table template |send request                                                        |
|post           |${POST_BODY_2} |to                   |${URL}                        |
|check          |response status|200                                                 |
|show           |response                                                            |
|register prefix|weather        |for namespace        |http://ws.cdyne.com/WeatherWS/|
|check          |xPath          |//weather:City/text()|@{City}                       |
*!

|send request       |
|zip  |City         |
|10007|New York     |
|94102|San Francisco|

(Result)

对于更复杂的请求,fixture also allows the usage of a Freemarker template(用于可选元素和迭代等)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    相关资源
    最近更新 更多