Nested DataSource loops
Hi, I am new to ReadAPI and API testing, so I’m learning as I go along…
I’m using data driven testing and have the following issue:
My rest request uses the customerID to get information about the customer’s accounts. So, the response is a json array that in its simplest form would look something like below (the real one has much more information per account):
{
"customerId" : “11111”,
"accounts" : [
{
"accountId" : "1",
"creationDate" : "2001-04-10",
"currentBalance" : "10.00"
},
{
"accountId" : "2",
"creationDate" : "2003-01-30",
"currentBalance" : "20.00"
},
{
"accountId" : "23",
"creationDate" : "2020-04-27",
"currentBalance" : "30.00"
}
]
}
My problem is that one customer may have 1 account and the next one 30 accounts. Data driven testing works with a fixed number of rows per iteration. In previous tests I used the listagg function to collect the information of multiple rows in a single row, but listagg will not work here because there is a lot of information per account, plus I have customers with more than 100 accounts!
So the way I solved this is with nested dataSource loops:
- The first SQL returns a bunch of customerIDs and the number of active accounts each customer has (dataSource1).
- Then comes the REST request for a customer ID
- Then I have a groovy script to test that the API ahs returned the number of accounts I expected
- Then another SQL script to fetch the customer’s account information: accountID, creation Date and currentBalance (dataSource2).
- Following is another groovy script to check that the accountID, creation Date and currentBalance of dataSource2 exist in the REST response
- Loop to Datasource2
- Loop to REST request
This solution works well but obviously apart from the initial query that it is fired only once, it also fires a database query once per customerID, so it is not as efficient as my previous tests where a single DB query was enough to satisfy the whole test.
My question is, has anyone used an alternative method that might be more time efficient?