Data Driven Testing in soapUI


hi there my name is Ole Lensmar I work
here at smart bear software in Stockholm Sweden I’m gonna do demo for you of the
data-driven functional testing features in SoapUI pro so if you’re using the
free version of soap UI please head over to soapui.org and download a trial of SoapUI Pro so you can hang on with the features have fun okay let’s get
started so I have here a very simple soapui I project I’ve imported a WSDL for a service that we are hosting here internally at smart bear and this
is a very simple inventory service where you can get items add items log in log
out such things like that and what I’m going to do is I’m going to do a data
driven test check that sum of expected items are actually in the inventory
database so to do that let’s just start by creating it a TestSuite and a test case
and we’ll start by adding the actual get item request which is what we’re going
to be using to to get the items that we want to validate so the default request
just contains this question mark for the ID and of course the the response we’re
getting back is just an error because that’s not what the service expects so
what we need to do here start by adding a datasource test step so this is one of
the cooler superior proof features let’s just add one of those and I have my
expected data set up in an excel sheet so I’m just going to select the Excel
data source up here as you can see there are a bunch of other possibilities JDBC
and files and directories and things like that
the file is here and let’s just have a quick look at that file so you see what
the data I have here so it’s very simple file just has five rows of IDs a name
and a cost of well not so imaginary smartphones and so what I’m going to do
is I’m going to make a call to the inventory with the ID and I’m going to
check that the the returned phone for each ID actually has the this expected
name and cost so to do that I need to add the same columns add in my excel
sheet I need to add those as properties here in my data source so there was one
ID name constant and just to test the data source we can just run this run
this little bit you can see the rows I’m getting back here and oh I missed one
thing here so you can see I’m actually getting the header row from the excel
sheet as well so I need to change this sort so a two so if I run that again
it’s just going to give me the actual IDs so great the data source is set up
let’s go back to the request so what I want to do is instead of sending a
question mark obviously I want to use the ID that’s been read up from the data
source so I’m using this right click get data wizard which will allow me to
select that ID property that I just created
in the data source and it’s going to generate the required property expansion
which will be basically replaced with the corresponding ID when the request is
being sent so if I just send that request as you can see here we’re
actually getting a phone back from the inventory because the current idea is
that the last row that we read into the data source but that’s not all I also
wanted to to validate that the actual cost and name of the phones I’m getting
back is the same as in the excel sheet so for that I’ll use standard XPath
assertions in subscribe but in the free version you have to
create those manually but in the pro version there is a very nice wizard so
you can just right click add assertion for content and it’s going to generate
the whole XPath statement and expected result for you
of course here I don’t want the expected result to be a fixed value and I want to
get that from the data source just as like I did with the ID so I’ll just use
the same get data wizard and same that and the same thing for the phone and
this get data wizard is available in most not all but in most edit fields in
Pro where you can use property expansions okay great so here probably
expansion for name and it selects the name from the responses will save that
you can see the assertions down here and when I send a request
probably the obviously the assertions will pass there it’s all matching up now
I’m ready for my data source so let’s go back to the test case and if I run this
test just as it is it’s only going to send one request but that’s not what I
intended I intended to send one request for each row in the data source so the
final touch here is to add a data source loop test step after the request down
here and the loop test step what it does is it’ll increment the data source to
the next row and if it has a next row so if it’s not at the end you tell it to
jump back to the request in our case so it’s going to basically loop you through
the data source and as long as it finds another row its jump back to the get
item request which will be executed and then the loop again until the data ends
so if I run this now you can see in the log down here that it’s actually around
this five requests one two three four five and you can in the log here of
course double click any requests and you can see the actual request I was sent
with this ID for example and this was the data we got back from the service
great so I have my data-driven test up and running before I run this
I’m just going to show you what happens if there’s a mismatch in the data so
let’s go back to the excel sheet and change the price of one of the phones
here save that and now run the test again and now we can see that test is
actually failing here because it expects the old price and the one I set it to
was the new one and this is not so unusual and what you might want to
happen here is not actually the test to stop but to continue to run on through
all the rows in your data source so there’s an option for that in the test
case options dialog it’s called the board on error and it’s checked by
defaults so you can just uncheck that and okay like that
and we’ll run the test again and as you can see now it’s failed but it still ran
round the remaining requests and since there was one failed test step it’ll
fail the entire test case at the end anyway so that’s it it’s real easy to
get started with data-driven testing in soapUI Pro hope you wish you good luck
with that bye bye

24 Comments

Add a Comment

Your email address will not be published. Required fields are marked *