📺 Develpreneur YouTube Episode

Video + transcript

Rest Assured and Karate - Part 3

2022-03-10 •Youtube

Detailed Notes

Our journey into Restful API Testing Using RestAssured begins by looking at the different ways in which API testing can be done. Next, we look at how to use tools such as the browser developer tool, Swagger, and Postman to test APIs from a browser. Additionally, we look at how to use libraries like RestAssued and Karate to build continuous integration tests for our code projects. Finally, we wrap up our discussion by showing you how to write RestAssured tests against a real-world scenario.

Restful API Testing Using RestAssured Overview:

Overview of Restful API Different Types of HTTP Requests How to Manually Test a Restful API Use Postman and Swagger Write RestAssured Unit Test What is Restful API

REST APIs provide a flexible, lightweight way to integrate applications, and have emerged as the most common method for connecting components in microservices architectures.

-IBM

HTTP Requests

Get - Requests a representation of the specified resource. Requests using GET should only retrieve data. Post -Submits an entity to the specified resource, often causing a change in state or side effects on the server. Put - Replaces all current representations of the target resource with the request payload. Delete - Deletes the specified resource. - Mozilla

RestAssured

REST Assured is a Java DSL for simplifying testing of REST-based services built on top of HTTP Builder. It supports POST, GET, PUT, DELETE, OPTIONS, PATCH, and HEAD requests and can be used to validate and verify the response of these requests.

- RestAssured

Start with a real-world example

To explain the principles of API testing we decided to begin with a real-world exercise and build out our test cases to support the following scenario. For instance, a company that wants to set up a Tutorial center at a university to help students study. Initially, they build a WS application that records the subjects that will be covered.

The current interface supports:

Create A Tutorial Retrieve All Tutorials Retrieve A Tutorial By Id Update A Tutorials By Id Find All Published Tutorials Find By Title Containing String Delete A Tutorial Delete All Tutorials

Restful API Testing Using RestAssured

Additional Resources

RestAssured Karate Postman Swagger Finally, this series comes from our mentoring/mastermind classes. These classes are virtual meetings that focus on how to improve our technical skills and build our businesses. After all the goals of each member vary. However, this diversity makes for great discussions and a ton of educational value every time we meet. We hope you enjoy viewing this series as much as we enjoy creating it. As always, this may not be all new to you, but we hope it helps you be a better developer.

Transcript Text
[Music]
okay our test bringing so let's go look
at the console there's our test
so we started spring boot
reset our data
we came in here the first thing we did
was a post
here's our api
we set the context to application json
as you can see here
our body contains the json object
our http response was actually 201
and the application came back was json
so if we look this guy should have
failed because i said 200
but we did get back the context
with our id of three
so then when we did our get we now have
three records returned so we see that
the first post worked
and the second post returned all three
however
the first one failed
because we did not get a 200 we actually
got a 201 so if i update this to 201
restart
and run our resistor demo again
and we see everything passed
that's because we received a 201 so we
got our 200 for our get a 201 for our
post
and our conditions passed now
all right so that's one and two
so now let's look at retrieving a
tutorial by id
and let's look at swagger real quick
so retrieving by id so we have to do a
get
tutorials by id
well we know we have one record out
there so let's try this guy out real
quick and just put one
and execute
so we have an id
a response should come back as 200
and we should return
a record and a response record should be
of type tutorial
and if you look here here is the url
that we need to
pass so let's look at how we set this up
so if we go over back to our code
so we have request we have base uri we
have get
so all this is the same with the
exception of our get so get
actually now requires an id
so we need to put in a token for id
and now we need to set the id value so
now we need to set a path param
and the parameter is going to be our
token there id
and
our value so in this case we want to
pass in one
just like we did over here so here's our
parameters
so we set our parameter
id
as one
and we added id to our get
so now this looks exactly like what we
have here in swagger
so now if i save this
and run again
we create the tutorial we retrieved all
tutorials and we retrieved a tutorial by
id so if i zoom up
the last call here
was to our get
so we passed in one
until we replaced our token
we got back at 200
application json
we set our path parameter id of 1
and we received back calculus so that
worked
so far so good pretty straightforward
all right so next we want to update by
id
and as you can see a lot of this is
pretty straightforward all you have to
do is follow some basic functionality of
how the apis are called
by id so we already have our id
so we've already defined our parameters
we've already set our api
however in this case we actually are
doing a put so if we go look over here
if we want to update we need to do a put
so put api tutorials id
requires the parameter id so all still
the same
this time though however we need to pass
in our body the tutorial value that we
want to update
and we're going to get back a response
again
for
the output
all right so here we have our given we
have our log
we have our base uri we have our
parameter
so there's two things we need to set
here so one
if we look back over here
we have to specify the application json
so in our
setup so we have base uri
we have
to set the context type
the application
based on
we've got that
we've got our path and now we need our
body
so to do the body we need to specify
some context so first we could do the
new like we did up here for the post
however i want to show you a different
way to do this so you can do this
another way so here instead of
setting the body you can actually set up
a json mapper
to do that you create a map collection
of a string
and object
and i'm showing you this in case you
don't have the pojo or don't have the
mapper
so if you do a json
as map
equals new
hash map
okay and then in here we're going to do
json
as a map
need to do that three times
because we need to set the
title description and published
so json map
we need to put
we need to put some information into our
collection
and now here we need to set our values
so we know we need title
we have our
description
and we have published
so if we don't have the pojo or we don't
have the entity being that we need to
build
this is a way for us to map it back so
if we go look
here and just look at this example
we see we have title description
published so we need to provide these
values here
in our put
so we see we have to have string string
and true
so we're going to come in title
string
some string
and this one will set to false
since we know calculus is already
published we will change it to something
else that's not published
so here i'm going to set our book title
to 2001
a space odyssey
and
again
a
another space
novel
and save
all right
so instead of doing the new
tutorial i'm actually defining our json
mapper now
to mimic
what we have to send in our header this
here
now we do not need to set id
because id is what we're actually going
to pass in as our lookup parameter to
set this value
all right so we have our log we have our
base uri we have our context type we're
setting our parameter
and now we need to set our body
to include our json mapper
is based on this map
including that
that looks good
and then we log and we should get 200.
so we'll save
rerun
and all of our test paths let's look at
our update here at the end
or report
so
we know one was calculus and math and
publish is true
we passed in
our body of description published in
true so this is our json map we
specified it as json and we set the path
parameter id as one so here's our put
and then what came back was id one
our new title our new description and
published as false
okay
that gives us four
now the rest of these are pretty
straightforward so i'm just going to
copy these down here and we're just
going to knock through them real quick
all right so we have five
five let's just simplify this for now
so five is find all published tutorials
and duplicate flagger
we want this one api tutorials published
there's no parameters there's no body
it's a straight up get
so we change this to a get
tutorials
published
we don't need body we don't need context
we just need the uri
and that should return to 200.
so that one's pretty straightforward and
that would be number five
okay save that
rerun
so that one ran and let's look at the
console
so as we see here we got back title
three four five and six all were
published true
now if we actually were to reset our
test we would only get back one of these
because we only had one hitchhiker's
guide to the galaxy
but it's interesting because we're
re-running this test continuously
against our in memory database it's just
going to keep stacking up these values
all right so now let's find a title
containing a string
so test 6
find by title containing string
and ironically enough
this is actually the first call we did
so if we actually go look back at
swagger
if we look we do not have a getter for
find
tutorials by string
if we look we have api tutorials
and if we expand that we see here that
we can pass in a optional title
so let's go back over here
so here we're going to need a
so we can kind of cheat we'll just go
back up here we'll need a path parameter
and this one will be type
and we want to look for
zero
i want to find the ones with 2001
and we just drop it back down to
tutorials
so our api we pass in the parameter
title
we just get api tutorials if you notice
we're not actually setting
anything here we're just setting the
path
parameters oops sorry wrong one yep so
not path parameters
this is actually a because this is a
path parameter this is actually a form
parameter so slightly different
so since this isn't a path but we need
to push this with the form
so this will be a form
parameter
now we call get api tutorials
so if i run this
refresh
and run our test again
everything passed if you notice we
created a tutorial we retrieved all
tutorials so we're just stacking up our
test so the last one here we were
looking for anything with a title of
zero
and since i restarted
our database
we got back one record you see here we
got back 2001 a space odyssey because
this is the only title with the zero
if you notice here if we go back one
since i restarted the microservice our
database reset and we only got back one
hitchhiker's guide to the galaxy
they're with me we're almost done
so next we want to delete
an individual tutorial and delete all
tutorials
so this will be delete a tutorial
and this is good for cleanup
so if you're running specific test data
and you have this option after you set
everything up you can go through and
delete everything and then validate that
your records were deleted
all right so again let's look at swagger
so we have two deletes here we have one
delete all one delete by id
we need to pass in a parameter for id
and we should get back a 200 that
everything was deleted
so
and this has to be a delete request so
instead of get we do delete
api tutorials by id
api tutorials
id
now this is not a form
perm path because we're updating the id
in the path
and this will be id
and
one
so delete
so we'll delete the first record
in the list and
actually let's delete
the second one
so we'll delete two
and
just test that we deleted this let's go
up and verify by id
yeah here we are retrieve the tutorial
by id so let's copy this guy
and add a second test to this one so
this will be 7
8
verify tutorial
was deleted
by id
and since we're doing two we'll follow
up with two
so it should return no record
so we should actually get back a 404
for no records found
and this delete will actually return us
a 204
all right so let's run this
this is running
our test is complete
it deleted our record and we verified it
was deleted so
the delete is right here so here's our
request
so we deleted we passed in the url the
api with our id of two
pathform id2
and we received back a 204.
and when we tried to validate it we
received a 404 because there was no
records found
okay and last but not least let's delete
all the records
and we're going to delete
all tutorials
and this will be nine
don't need
that
and our delete
should be back
and 204 double check our swagger
delete api tutorials
no parameters
and it should delete everything
all right so if i run this
everything work except delete a tutorial
that's because we actually
had already deleted number two
and therefore it's not there
so what we need to do for this
particular test is restart the database
restart the microservice for the api
with the database menu
once that's restarted then we can rerun
the test
and everything passed
so if we look at our last command here
we called our request
delete
api tutorials
everything deleted it returned back to
204
so now if we actually come over here to
swagger so i could write one more method
to double check this but what we can do
is we can go here to get api tutorials
click try out
hit execute
so it returned nothing
we have no body
alright so that is rest assured in a
nutshell so we walk through the
different types of commands here
so let's go back and just briefly go
over this
so we went through the different ways
you can use rest assured to
set up your request header
we define our base uri we can set
contact type we can pass in a body
either through a object
or
using a json mapper
we can post information
we can get information
we can use the path parameter id to set
an id on the url
we can validate the statuses of the
requests coming back using the status
code
we can also define our context type
within a request and within our response
we can also do
forms so we can pass form information if
it does not need to be in the url
and we went through using the delete and
verifying a delete
so are there any questions
so michael i know when it turns green
and that's when you know like the api
ran successfully
so um is there a way
like uh whereby you
you can let me say manipulate it and and
it turns green maybe
or
maybe you can throw in on a failure in
api because then anytime i run it
usually most of the time like
it comes out green all the time which
means it's uh
i mean i'm a tester because usually i
wouldn't know what goes on behind the
scenes so
these are all predefined tests
so depending upon your test data
if you're trying to test to make sure
everything returns correctly your
validation points in our case here the
status code
is going to be our assertion
so if you're unsure of what the test is
checking you can go look at the test and
then look at what is being asserted so
you could have an assert method here or
some type a status code within the rest
assured
with that being said though you really
want your test to always be green
because if it's not green then that
means that either a code change that was
deployed broke something
or the requirements that you're actually
testing against have changed and you
need to go update the test case or test
data to reflect the changes to the
requirements
okay okay
any other questions
not so much a question as much as just
sort of a
a statement i think to follow up with
these as we you know we've done a couple
of these now
the tools for testing
particularly at this level and it almost
it's funny so as i go through some of
these you know watch some of these
presentations is it's almost an itch to
build out proper testing
and i think it just points to it's
become such a
such an easy thing to do in many cases
when you include the tools you look at
the power of them and how easy it is to
just script out some tests
it to me it makes more sense than ever
for developers to
definitely be a part of it and be
building out some of their tests at
least their unit tests
and you know assisting qa more and
particularly when you look at like you
know sprints and
the scrum approach and things like that
where it's not
a you know sort of like a wall between
developers and qa but a partnership
um these kind of tools just make this
make that much more
easy to do and almost hard to argue
against it it's like you know how much
how much effort is it really going to
take other than thinking through some of
these tests
to build them out and particularly when
you're coding them in the first place
you almost those things almost fall into
place it's you know it's obviously test
driven development things like that make
that more uh push you to do that
but even if you're not taking that
approach it seems like you know testing
is almost a slam dunk at this point
exactly and it really should be because
even after i did all the presentations
on integrating testing in your
development cycle
really testing should be a no-brainer at
this point
i mean we've been in the coding now for
well over two decades and
this whole idea of
we need to separate qa from testing
really is a joke at this point
really if you want to write good code
especially in the microsoft world you
have to think from the end point so
basically you have to start with your
test what it is that you're trying to do
and then write your code for it because
if you do it the other way you're
really risking what is it that this
microservice is really going to do for
you
and the other way of thinking this way
is
as a developer
at the end when you're done writing your
code you know how to test your code you
know how it was tested now granted you
may make mistakes and what you write for
your test cases but as you get better at
this when you hand it off to qa or a qa
person comes in and tests your code
there should be almost no barrier there
they should be able to just look at the
code look at the test case and say ah
okay here's how i test it it's working
it's not working
where did it fail how can i go research
it it should be all transparent there
should be
little or no back and forth between qa
and development
gotcha cool yeah i think so that's a
good suggestion
right with that
i'd like to thank you guys for your time
if you want to talk about any of these
topics further or some other topics we
haven't touched on yet
send your comments and questions to us
at info developer.com you can hit us on
the contact us page on developernerd.com
website
you can search for us on youtube under
developerner and we're also on vimeo.com
developernerd
our goal is making every developer
better have a great day
you
Transcript Segments
0.48

[Music]

26.32

okay our test bringing so let's go look

28.32

at the console there's our test

31.92

so we started spring boot

34.16

reset our data

36.48

we came in here the first thing we did

38.559

was a post

40.399

here's our api

43.52

we set the context to application json

47.92

as you can see here

49.92

our body contains the json object

54.32

our http response was actually 201

58.64

and the application came back was json

62.32

so if we look this guy should have

64.96

failed because i said 200

67.76

but we did get back the context

70.96

with our id of three

73.52

so then when we did our get we now have

76.24

three records returned so we see that

78.4

the first post worked

80.96

and the second post returned all three

83.28

however

84.96

the first one failed

87.759

because we did not get a 200 we actually

90.799

got a 201 so if i update this to 201

95.119

restart

97.04

and run our resistor demo again

100.799

and we see everything passed

103.439

that's because we received a 201 so we

106.88

got our 200 for our get a 201 for our

109.68

post

110.64

and our conditions passed now

114.24

all right so that's one and two

116.56

so now let's look at retrieving a

118.64

tutorial by id

121.36

and let's look at swagger real quick

124.719

so retrieving by id so we have to do a

127.759

get

128.72

tutorials by id

130.879

well we know we have one record out

132.4

there so let's try this guy out real

133.92

quick and just put one

136

and execute

138.48

so we have an id

140.239

a response should come back as 200

143.44

and we should return

145.599

a record and a response record should be

148.64

of type tutorial

150.4

and if you look here here is the url

153.28

that we need to

154.84

pass so let's look at how we set this up

158.48

so if we go over back to our code

162.239

so we have request we have base uri we

165.36

have get

167.36

so all this is the same with the

170.64

exception of our get so get

173.84

actually now requires an id

177.36

so we need to put in a token for id

180.56

and now we need to set the id value so

184

now we need to set a path param

186.959

and the parameter is going to be our

188.8

token there id

191.04

and

191.84

our value so in this case we want to

194.4

pass in one

196.239

just like we did over here so here's our

198.72

parameters

202.159

so we set our parameter

204.48

id

205.84

as one

206.959

and we added id to our get

210.48

so now this looks exactly like what we

212.319

have here in swagger

215.28

so now if i save this

217.68

and run again

220.319

we create the tutorial we retrieved all

222.959

tutorials and we retrieved a tutorial by

225.84

id so if i zoom up

228.72

the last call here

231.36

was to our get

233.84

so we passed in one

235.68

until we replaced our token

237.599

we got back at 200

239.439

application json

241.12

we set our path parameter id of 1

244.56

and we received back calculus so that

247.04

worked

248.959

so far so good pretty straightforward

251.28

all right so next we want to update by

253.84

id

255.599

and as you can see a lot of this is

257.44

pretty straightforward all you have to

259.28

do is follow some basic functionality of

263.28

how the apis are called

266.08

by id so we already have our id

269.199

so we've already defined our parameters

272.24

we've already set our api

275.759

however in this case we actually are

277.919

doing a put so if we go look over here

282.639

if we want to update we need to do a put

286

so put api tutorials id

288.88

requires the parameter id so all still

291.52

the same

292.8

this time though however we need to pass

295.199

in our body the tutorial value that we

297.919

want to update

299.759

and we're going to get back a response

301.52

again

302.56

for

303.36

the output

305.36

all right so here we have our given we

307.84

have our log

309.52

we have our base uri we have our

312.24

parameter

313.52

so there's two things we need to set

315.28

here so one

317.44

if we look back over here

319.44

we have to specify the application json

324.96

so in our

326.8

setup so we have base uri

329.919

we have

330.96

to set the context type

333.759

the application

335.759

based on

337.44

we've got that

338.72

we've got our path and now we need our

341.44

body

342.96

so to do the body we need to specify

346.96

some context so first we could do the

350.84

new like we did up here for the post

354.24

however i want to show you a different

355.919

way to do this so you can do this

358

another way so here instead of

360.72

setting the body you can actually set up

362.88

a json mapper

364.639

to do that you create a map collection

367.28

of a string

369.28

and object

371.6

and i'm showing you this in case you

373.44

don't have the pojo or don't have the

375.52

mapper

376.96

so if you do a json

379.039

as map

381.199

equals new

383.84

hash map

386.479

okay and then in here we're going to do

389.44

json

391.44

as a map

393.759

need to do that three times

396.72

because we need to set the

399.759

title description and published

402.56

so json map

404.319

we need to put

407.039

we need to put some information into our

408.96

collection

411.039

and now here we need to set our values

413.68

so we know we need title

416

we have our

417.28

description

420.8

and we have published

424.8

so if we don't have the pojo or we don't

427.44

have the entity being that we need to

429.599

build

430.639

this is a way for us to map it back so

433.36

if we go look

434.84

here and just look at this example

438.16

we see we have title description

440.56

published so we need to provide these

443.039

values here

444.639

in our put

446.24

so we see we have to have string string

448.96

and true

451.199

so we're going to come in title

454.56

string

456.8

some string

458.56

and this one will set to false

461.68

since we know calculus is already

463.759

published we will change it to something

465.759

else that's not published

467.599

so here i'm going to set our book title

470

to 2001

471.919

a space odyssey

474.72

and

476.16

again

477.199

a

478.72

another space

480.8

novel

483.36

and save

484.879

all right

486.479

so instead of doing the new

488.72

tutorial i'm actually defining our json

491.52

mapper now

493.28

to mimic

494.72

what we have to send in our header this

497.52

here

498.639

now we do not need to set id

500.96

because id is what we're actually going

503.199

to pass in as our lookup parameter to

505.759

set this value

507.12

all right so we have our log we have our

509.28

base uri we have our context type we're

511.52

setting our parameter

513.76

and now we need to set our body

517.2

to include our json mapper

520.479

is based on this map

522.479

including that

524

that looks good

525.76

and then we log and we should get 200.

528.16

so we'll save

530

rerun

531.92

and all of our test paths let's look at

533.92

our update here at the end

535.839

or report

537.519

so

539.2

we know one was calculus and math and

541.839

publish is true

543.44

we passed in

545.36

our body of description published in

547.839

true so this is our json map we

549.92

specified it as json and we set the path

552.64

parameter id as one so here's our put

556.48

and then what came back was id one

560.32

our new title our new description and

563.2

published as false

566.959

okay

567.92

that gives us four

570

now the rest of these are pretty

571.76

straightforward so i'm just going to

573.44

copy these down here and we're just

575.12

going to knock through them real quick

579.279

all right so we have five

591.04

five let's just simplify this for now

595.76

so five is find all published tutorials

608.16

and duplicate flagger

610.959

we want this one api tutorials published

613.839

there's no parameters there's no body

616

it's a straight up get

620.16

so we change this to a get

624.079

tutorials

628

published

629.279

we don't need body we don't need context

631.6

we just need the uri

634.079

and that should return to 200.

636.48

so that one's pretty straightforward and

638.24

that would be number five

642.16

okay save that

644.16

rerun

646.16

so that one ran and let's look at the

648.399

console

650.399

so as we see here we got back title

652.88

three four five and six all were

655.44

published true

657.2

now if we actually were to reset our

660.24

test we would only get back one of these

662.56

because we only had one hitchhiker's

664.079

guide to the galaxy

665.6

but it's interesting because we're

667.36

re-running this test continuously

669.519

against our in memory database it's just

672.24

going to keep stacking up these values

676.32

all right so now let's find a title

678.16

containing a string

682.24

so test 6

687.44

find by title containing string

691.92

and ironically enough

696.32

this is actually the first call we did

700.48

so if we actually go look back at

702.16

swagger

703.519

if we look we do not have a getter for

707.2

find

708.079

tutorials by string

710.079

if we look we have api tutorials

713.04

and if we expand that we see here that

715.36

we can pass in a optional title

719.36

so let's go back over here

722.16

so here we're going to need a

724.639

so we can kind of cheat we'll just go

726.48

back up here we'll need a path parameter

729.6

and this one will be type

733.519

and we want to look for

736.959

zero

738.399

i want to find the ones with 2001

741.279

and we just drop it back down to

743.92

tutorials

745.44

so our api we pass in the parameter

747.76

title

748.959

we just get api tutorials if you notice

751.839

we're not actually setting

753.76

anything here we're just setting the

755.839

path

756.839

parameters oops sorry wrong one yep so

760.16

not path parameters

761.92

this is actually a because this is a

764.72

path parameter this is actually a form

767.68

parameter so slightly different

770.88

so since this isn't a path but we need

773.36

to push this with the form

775.76

so this will be a form

778.639

parameter

782.32

now we call get api tutorials

785.12

so if i run this

787.92

refresh

789.839

and run our test again

792.399

everything passed if you notice we

794.48

created a tutorial we retrieved all

796.48

tutorials so we're just stacking up our

799.04

test so the last one here we were

801.519

looking for anything with a title of

803.68

zero

805.04

and since i restarted

807.36

our database

809.2

we got back one record you see here we

811.76

got back 2001 a space odyssey because

814

this is the only title with the zero

817.2

if you notice here if we go back one

818.959

since i restarted the microservice our

821.839

database reset and we only got back one

824

hitchhiker's guide to the galaxy

826.16

they're with me we're almost done

828.88

so next we want to delete

831.279

an individual tutorial and delete all

834.24

tutorials

835.839

so this will be delete a tutorial

840.88

and this is good for cleanup

842.88

so if you're running specific test data

845.6

and you have this option after you set

847.76

everything up you can go through and

849.279

delete everything and then validate that

851.279

your records were deleted

854.079

all right so again let's look at swagger

857.12

so we have two deletes here we have one

859.92

delete all one delete by id

863.519

we need to pass in a parameter for id

867.12

and we should get back a 200 that

870.24

everything was deleted

873.12

so

874

and this has to be a delete request so

877.36

instead of get we do delete

881.839

api tutorials by id

885.44

api tutorials

888.88

id

890

now this is not a form

892.56

perm path because we're updating the id

895.04

in the path

899.76

and this will be id

902.88

and

904.16

one

906.8

so delete

908.079

so we'll delete the first record

910.56

in the list and

913.36

actually let's delete

916

the second one

917.76

so we'll delete two

920.8

and

921.6

just test that we deleted this let's go

923.76

up and verify by id

926.56

yeah here we are retrieve the tutorial

928.16

by id so let's copy this guy

931.6

and add a second test to this one so

934.399

this will be 7

936.32

8

938.32

verify tutorial

940.399

was deleted

942.16

by id

943.519

and since we're doing two we'll follow

945.44

up with two

946.88

so it should return no record

949.519

so we should actually get back a 404

953.44

for no records found

955.839

and this delete will actually return us

958.72

a 204

961.92

all right so let's run this

964.56

this is running

968.399

our test is complete

970.16

it deleted our record and we verified it

972.56

was deleted so

974.48

the delete is right here so here's our

977.04

request

978.88

so we deleted we passed in the url the

982.079

api with our id of two

985.44

pathform id2

988.079

and we received back a 204.

990.8

and when we tried to validate it we

992.88

received a 404 because there was no

995.759

records found

998.079

okay and last but not least let's delete

1001.519

all the records

1003.759

and we're going to delete

1005.759

all tutorials

1007.279

and this will be nine

1009.68

don't need

1011.279

that

1013.199

and our delete

1015.12

should be back

1018

and 204 double check our swagger

1022.24

delete api tutorials

1024.48

no parameters

1026

and it should delete everything

1028.48

all right so if i run this

1032.16

everything work except delete a tutorial

1035.919

that's because we actually

1038.4

had already deleted number two

1040.88

and therefore it's not there

1043.12

so what we need to do for this

1044.64

particular test is restart the database

1047.6

restart the microservice for the api

1050.08

with the database menu

1053.039

once that's restarted then we can rerun

1055.28

the test

1057.919

and everything passed

1060.559

so if we look at our last command here

1064.4

we called our request

1066.64

delete

1068.16

api tutorials

1070.24

everything deleted it returned back to

1072.16

204

1073.44

so now if we actually come over here to

1075.12

swagger so i could write one more method

1077.039

to double check this but what we can do

1079.44

is we can go here to get api tutorials

1082.72

click try out

1084.4

hit execute

1086.4

so it returned nothing

1089.36

we have no body

1091.6

alright so that is rest assured in a

1093.919

nutshell so we walk through the

1095.6

different types of commands here

1098.4

so let's go back and just briefly go

1100.559

over this

1102.08

so we went through the different ways

1104.32

you can use rest assured to

1106.96

set up your request header

1109.919

we define our base uri we can set

1112.16

contact type we can pass in a body

1115.52

either through a object

1118.559

or

1119.76

using a json mapper

1122.96

we can post information

1125.84

we can get information

1128.64

we can use the path parameter id to set

1131.52

an id on the url

1134.559

we can validate the statuses of the

1137.039

requests coming back using the status

1139.52

code

1140.88

we can also define our context type

1142.96

within a request and within our response

1147.039

we can also do

1148.64

forms so we can pass form information if

1151.44

it does not need to be in the url

1154.88

and we went through using the delete and

1157.039

verifying a delete

1159.84

so are there any questions

1162.88

so michael i know when it turns green

1165.919

and that's when you know like the api

1167.52

ran successfully

1169.6

so um is there a way

1172.08

like uh whereby you

1174.08

you can let me say manipulate it and and

1176.64

it turns green maybe

1178.64

or

1179.6

maybe you can throw in on a failure in

1181.76

api because then anytime i run it

1183.6

usually most of the time like

1186.24

it comes out green all the time which

1187.919

means it's uh

1189.12

i mean i'm a tester because usually i

1190.64

wouldn't know what goes on behind the

1192.16

scenes so

1194

these are all predefined tests

1196.32

so depending upon your test data

1198.799

if you're trying to test to make sure

1200.48

everything returns correctly your

1203.28

validation points in our case here the

1205.919

status code

1207.52

is going to be our assertion

1210.32

so if you're unsure of what the test is

1213.12

checking you can go look at the test and

1215.6

then look at what is being asserted so

1217.52

you could have an assert method here or

1219.84

some type a status code within the rest

1222.32

assured

1223.6

with that being said though you really

1225.679

want your test to always be green

1227.919

because if it's not green then that

1230

means that either a code change that was

1232.32

deployed broke something

1234.48

or the requirements that you're actually

1236.72

testing against have changed and you

1238.88

need to go update the test case or test

1241.039

data to reflect the changes to the

1243.2

requirements

1244.48

okay okay

1247.039

any other questions

1249.52

not so much a question as much as just

1251.679

sort of a

1253.28

a statement i think to follow up with

1254.88

these as we you know we've done a couple

1256.88

of these now

1258.4

the tools for testing

1260.799

particularly at this level and it almost

1263.36

it's funny so as i go through some of

1265.039

these you know watch some of these

1266.159

presentations is it's almost an itch to

1269.039

build out proper testing

1271.44

and i think it just points to it's

1273.28

become such a

1275.76

such an easy thing to do in many cases

1278.48

when you include the tools you look at

1279.84

the power of them and how easy it is to

1281.52

just script out some tests

1283.52

it to me it makes more sense than ever

1286.72

for developers to

1288.799

definitely be a part of it and be

1290.88

building out some of their tests at

1292.24

least their unit tests

1294

and you know assisting qa more and

1296.32

particularly when you look at like you

1297.6

know sprints and

1299.039

the scrum approach and things like that

1300.96

where it's not

1302.4

a you know sort of like a wall between

1304.559

developers and qa but a partnership

1308.08

um these kind of tools just make this

1310.88

make that much more

1313.039

easy to do and almost hard to argue

1315.039

against it it's like you know how much

1317.2

how much effort is it really going to

1318.72

take other than thinking through some of

1320.24

these tests

1321.76

to build them out and particularly when

1323.36

you're coding them in the first place

1324.88

you almost those things almost fall into

1326.72

place it's you know it's obviously test

1328.72

driven development things like that make

1330.48

that more uh push you to do that

1333.84

but even if you're not taking that

1335.12

approach it seems like you know testing

1336.88

is almost a slam dunk at this point

1340.559

exactly and it really should be because

1342.72

even after i did all the presentations

1344.64

on integrating testing in your

1346.64

development cycle

1348

really testing should be a no-brainer at

1349.76

this point

1350.799

i mean we've been in the coding now for

1352.96

well over two decades and

1355.679

this whole idea of

1358.32

we need to separate qa from testing

1360.72

really is a joke at this point

1362.96

really if you want to write good code

1364.72

especially in the microsoft world you

1366.72

have to think from the end point so

1369.44

basically you have to start with your

1370.96

test what it is that you're trying to do

1372.799

and then write your code for it because

1374.96

if you do it the other way you're

1377.6

really risking what is it that this

1379.84

microservice is really going to do for

1381.84

you

1382.96

and the other way of thinking this way

1385.36

is

1386.799

as a developer

1388.4

at the end when you're done writing your

1390.4

code you know how to test your code you

1393.2

know how it was tested now granted you

1395.6

may make mistakes and what you write for

1397.36

your test cases but as you get better at

1399.84

this when you hand it off to qa or a qa

1403.12

person comes in and tests your code

1405.039

there should be almost no barrier there

1407.919

they should be able to just look at the

1409.36

code look at the test case and say ah

1411.44

okay here's how i test it it's working

1413.84

it's not working

1415.679

where did it fail how can i go research

1417.76

it it should be all transparent there

1419.52

should be

1420.4

little or no back and forth between qa

1422.4

and development

1424.4

gotcha cool yeah i think so that's a

1427.279

good suggestion

1429.84

right with that

1431.279

i'd like to thank you guys for your time

1433.679

if you want to talk about any of these

1435.039

topics further or some other topics we

1437.679

haven't touched on yet

1439.2

send your comments and questions to us

1441.12

at info developer.com you can hit us on

1444.64

the contact us page on developernerd.com

1446.88

website

1447.84

you can search for us on youtube under

1450

developerner and we're also on vimeo.com

1453.12

developernerd

1454.4

our goal is making every developer

1456

better have a great day

1474.4

you