Using fitnesse to test services based on xml over http

1.2k Views Asked by At

I’m struggling to come up with a good approach to write automated acceptance tests for services based on xml over http using Fitnesse. These services have complex requests and responses with xml-elements from schemas that are not shared between services. I don’t want to create tremendous amounts of Fixture-code to build up requests, marshaling/unmarshaling and do http-invoking for each service.

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. 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.

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. In either case I would be back to writing expensive plumbing. Does anyone here have some thoughts on this?

1

There are 1 best solutions below

0
On

I've created a fixture to tackle this problem without any additional coding: XmlHttpTest. Creating the request is not dealt with using (custom) Java code mimicking the XML structure. Instead it is dealt with as generating a text value where placeholders need to be replaced. Checks are performed using XPath expressions.

Sample usage (extracted from one of the project's GitHub wiki pages) for a single call:

!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).