3

I am working on a REST-API that validates data (system to system communication). This data is described in XML. The content of the XML is validated using business rules which are implemented in the system. I would like to define scenario's with the client (the three amigos) that test the validation of example XML data-files. How would I go about this?

In my view, I have two options: 1) describe the XML-data as input 2) reference to an existing document.

1)

Scenario Outline: Add valid document
  Given I have the following XML
  """


     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <element>
          .....
        </element>

  """

  When I POST this XML

  Then results should not contain value `<code>` at path `<xpath>`

  Examples:

    | xpath             | code        |

    | /xpath/expression |  ERROR_CODE |  

2)

Given I have XML with id 1
When I post this XML
Then results should not contain value `<code>` at path `<xpath>`

      Examples:

        | xpath             | code        |

        | /xpath/expression |  ERROR_CODE |  

Option 1 might be a bit too technical, but to be noted here is that the business knows about validating data, what fields are validated and the expected validation errors. The benefit to this approach is that the test-data is separately defined from the system and is combined with the test-case

Option 2 is better to understand but you are bound to the data which is already in the system.

Do you have any opinions about this?

  • 1
    I would go for option 1, for easy maintenance and test data separation. – Yu Zhang Mar 7 '17 at 9:47
0

We chose to create Object builders which translate to XML-definitions in the Stepdefinitions (a third option) and use these in the scenario's.

Then functionally we can define an object structure in our feature files:

Given I have an object
And Object has id 123
And Object has property foo
And Object has ...
When I post this object
Then I should receive ...

In our stepdefinitions we translate this object to an xml structure.

ObjectBuilder builder = new ObjectBuilder();
builder.setId(..);
builder.setProperty(..);
builder.toXML();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.