简体   繁体   English

使用Fitnesse通过HTTP测试基于xml的服务

[英]Using fitnesse to test services based on xml over http

I'm struggling to come up with a good approach to write automated acceptance tests for services based on xml over http using Fitnesse. 我正在努力想出一个好的方法,使用Fitnesse为基于xml的xml编写服务的自动接受测试。 These services have complex requests and responses with xml-elements from schemas that are not shared between services. 这些服务具有来自服务之间不共享的模式的xml元素的复杂请求和响应。 I don't want to create tremendous amounts of Fixture-code to build up requests, marshaling/unmarshaling and do http-invoking for each service. 我不想创建大量的Fixture代码来建立请求,封送/拆组并为每个服务进行http调用。

I've looked into the RestFixture(https://github.com/smartrics/RestFixture) which seems to as a great approach to limit the plumbing effort for testing these kind of services. 我已经研究过RestFixture(https://github.com/smartrics/RestFixture),这似乎是限制测试此类服务的管道工作的一种好方法。 The only problem is generating the request in a good way. 唯一的问题是以一种很好的方式生成请求。 For “real” rest services this would not be a problem, but my services requires a lot of xml in the request-body. 对于“真正的”休息服务,这将不是问题,但是我的服务在请求正文中需要大量xml。

I would like to somehow allow the tester to build up their request using a Scenario table, but since all the services uses different schemas it can't see how I can do this without creating a really complex backing-fixture responsible for creating all the different request or several Fixtures each responsible for generating request for one service. 我想以某种方式允许测试人员使用Scenario表建立他们的请求,但是由于所有服务都使用不同的架构,因此如果不创建一个负责创建所有不同组件的非常复杂的支持程序,就看不到我如何做到这一点。一个或多个夹具,每个夹具负责为一项服务生成请求。 In either case I would be back to writing expensive plumbing. 无论哪种情况,我都将重新编写昂贵的管道。 Does anyone here have some thoughts on this? 这里有人对此有想法吗?

I've created a fixture to tackle this problem without any additional coding: XmlHttpTest . 我创建了一个无需任何其他代码即可解决此问题的装置: XmlHttpTest Creating the request is not dealt with using (custom) Java code mimicking the XML structure. 使用模仿XML结构的(自定义)Java代码不会处理创建请求。 Instead it is dealt with as generating a text value where placeholders need to be replaced. 而是将其视为生成需要替换占位符的文本值。 Checks are performed using XPath expressions. 使用XPath表达式执行检查。

Sample usage (extracted from one of the project's GitHub wiki pages ) for a single call: 单个调用的示例用法(从项目的GitHub Wiki页面中提取):

!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) (结果)

Or (using scenario to make multiple calls) 或(使用场景进行多次通话)

!*> 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 ) 结果

For more complex requests the fixture also allows the usage of a Freemarker template (for things like optional elements and iteration). 对于更复杂的请求, fixture还允许使用Freemarker模板 (用于可选元素和迭代之类的东西)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM