0

I'm creating an API testing framework, and to avoid having a test class containing 1000's of lines of code I'm looking at creating separate classes which will hold the xml data, which I'll then call in my test.

My initial thoughts were to create a payload class which would contain the XML elements for my test(an example is below)

public class CreateOrderPayload
{
    public static string OrderPayload()
    {
        XDocument OrderData = new XDocument();
        XElement root = new XElement("Order");
        DateTime now = DateTime.Now;

        root.Add(new XElement("BillingAddress",
            new XElement("AddressLine1", "Canada adress 17"),
            new XElement("AddressLine2", "ccc"),
        root.Add(new XElement("Customer",
            new XElement("ContactNumber", "ContactNum"),
            new XElement("EmailAddress", "andy@test.com"),
        root.Add(new XElement("OriginalOrderId", "2315923148"));
        root.Add(new XElement("Source", "fffff"));

        OrderData.Add(root);

        return OrderData.ToString();
    }
}

In my actual test I'd then look to call the above class so that I can grab the payload to use for my test. I'm using RestSharp to do this so would initialise my test with something like the below:

        restClient = new RestClient(Constants.CRCOrderApi);
        restRequest = new RestRequest(Method.POST);

What I'm trying to work out is how I would grab the XML from my CreateOrderPayload class to pass across into my test?

  • Isn't it the same issue you have raised in sqa.stackexchange.com/questions/35896/… ? – Alexey R. Oct 4 '18 at 14:22
  • not to my mind, no – Andy Tilston Oct 4 '18 at 14:28
  • why bother to create the xml with an object if you are only ever going to statically return it as a string ? – Amias Oct 5 '18 at 12:49
  • Hi Amias, whilst I am statically returning it as a string at the moment I want to flesh out the framework so that different values can be passed if need be – Andy Tilston Oct 5 '18 at 13:34
1

Its generally a good idea for a test framework to have data classes representing any of the common data interchange formats.

My instinct here would be to make an object thats constructor can take an XML file as an arg , then parse it filling out fields as members.

You could provide a generic data class that all your data classes inherit from to give them consistant behaviour or interfaces, this can help with maintenance later.

This helps when you get want to test more than the happy path and will keep the code in your tests easier to read and manage.

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.