►
From YouTube: Writing Tests for Azure Functions
Description
In this episode, Senior Program Manager Jeff Hollan (@jeffhollan) comes on to show us how we can get started with testing our Azure Functions apps. He walks through some examples of doing both unit testing as well as integration testing. We also learn about some of the tools and frameworks that help make testing easier.
[00:45] - Highlights from Microsoft Ignite 2018
[02:10] - Setting up mocks for Azure Functions
[10:00] - Why and how to do Integration testing
A
So
other
function
is
a
great
way
to
write
serverless
applications
on
top
of
the
cloud,
but
you
know
we
want
to
know
how
we
could
test
these
functions.
So
in
this
episode,
I'm
gonna
have
Jeff
Hollen
come
on
and
let
us
know
exactly
how
we
can
get
involved
in
unit
testing.
Our
Azure
functions
in
this
episode
of
the
odd
night
Metro.
A
A
B
Sure
the
the
big
moment
at
ignite
was
as
your
functions
version.
2
became
generally
available.
So
what
that
means
is
you
know
it's
a
new
version.
It's
bigger!
It's
better!
It's
faster!
It's
actually
smaller.
When
we
first
released
as
your
functions,
it
was
written
on
top
of
dotnet
framework
4.7,
you
know
or
even
4.6,
so
we
rewrote
the
entire
host.
We
made
a
bunch
of
enhancements
performance
improvements,
extensibility
improvements,
and
it's
now
written
in
dotnet
core
to
one.
B
So
that
means
that
as
a
developer,
now
you
can
write
functions
targeting
that
core
to
one
you
get
some
nice
performance
benefits
from
that
enables
to
do
more
things
like
start
to
light
up
new
triggers
or
bindings.
So
one
of
the
things
we
talked
about
ignite
2
was,
you
know
we
have
a
new
binding
for
signal
R,
so
you
can
add,
your
functions.
Talk
to
signal
are
and
if
anyone
wants
to
write
their
own
bindings
for
some
other
service,
that's
also
available
too.
B
A
A
Gonna,
be
that's
gonna
be
exciting
with
so
so,
for
this
term,
particularly
I
think
we're
to
talk
about
some.
That's
a
little
bit
more
fundamental
for
functions
developers.
So
you
know
I,
you
know:
I
love,
visual
studio
and
I
like
to
be
able
to
be
able
to
debug
and
run
my
functions
on
my
local
machine,
but
I
also
want
to
be
able
to
do
unit
tests
too,
and
that's
the
question
so
I
hear
a
lot
of
customers
asking
yeah
like
how
can
I
do.
A
B
And
this
is
something
I
hear
a
lot
too,
and
one
of
the
I
guess
challenges
with
with
functions
or
at
least
differences
is
that
it's
very
opinionated
like
like.
We
expect
a
certain
method
signature.
We
expect
a
certain
amount
of
parameters.
We
are
we
ourselves
as
a
service
you're,
going
to
be
in
charge
of
like
instantiating,
your
method,
creating
your
your
invocation,
so
it
can
be
a
little
bit
foreign
to
people
who
are
looking
at
this
and
saying
I.
B
Don't
have
the
same
controls
that
I'm
used
to
having
like
I
can't
make
these
method
be
everything
that
I
want
I
might
not
be
able
to
inject
dependencies
in
the
same
way
I'm
used
to
so
what
does
that
mean
from
once?
I
need
to
make
this
testable
and
using
all
of
the
frameworks
time
you
start
doing
so.
The
good
news
is
it's
not
as
scary
as
it
sounds,
but
it
is
still
worth
looking
at
and
doing
so.
I
can
even
walk
through
a
quick
example.
Here.
B
I've
got
something
very
simple
for
my
machine,
and
this
is
just
a
simple
Azure
function.
I
kept
it
as
simple
as
I,
possibly
could
using
the
new
version
to
run
time.
I'm
gonna
get
an
HTTP
request.
I
need
to
look
at
that
request
and
there's
going
to
be
a
query
parameter
with
a
number
and
all
I
need
to
do
is
detect.
Is
this
going
to
be
an
odd
number
or
an
even
number
and
I've
done
some
improvement
recently?
B
A
If
we
take
a
look
at
the
function
really
quickly,
so
as
a
person
that
I'm
going
to
write
unit
tests,
I
got
to
be
able
to
create
my
own
HTTP
requests,
yeah
right
and
then
I
got
to
create
an
instance
of
that
logger
yeah,
because
I
got
to
pass
those
dependencies
right.
I
got
to
pass
those
parameters
into
the
function.
Alright.
So
how
do
we?
How
do
we
do
that?
Yeah.
B
So
I
added
just
to
my
solution,
a
test
project.
This
is
using
X
unit,
specifically
targeting
dotnet
core
2
and
then
I've
written
one
for
like
my
odd
or
even
the
one,
we're
looking
at
here's
where
I
run
my
test
for
this
function.
So
I
have
a
few
unit
tests
here,
like
one
check,
if
it's
an
even
number
check,
if
it's
an
odd
number
and
then
check
if
I
pass
in
something,
that's
not
a
number
and
I've
written.
B
Some
things
to
help
me
like
I
I,
do
need
to
generate
an
HTTP
request
as
Reventon,
and
so
I
can
actually
just
go
straight
to
this
definition
and
here's
where
I'm
generating
my
own
HTTP
requests.
So
I
have
you
know:
I've
created
an
HTTP
request,
I'm
creating
the
write,
query
parameter
and
then
I
return
that
request
back.
I
could
do
this
with
a
mocking
framework
if
I
wanted
to,
but
in
this
case
I've
actually
just
created
a
completely
valid
HTTP
request
to
pass
in
that
I'm
reusing
for
all
of
my
tests.
B
Sure
and
then
I
can
I
execute
the
function.
All
as
your
functions
today
are
static
and
they're
public
as
well.
So
I
just
say
you
know
odd
or
even
dot
run
I
pass
in
that
HTTP
request.
I
pass
in
that
logger,
which
is
an
implement
instance
of
an
OL
logger.
We
use
the
dotnet
cores
ilogger
abstraction
so
that
you
can
pass
in
whatever
custom
longer
you
want
I'm,
just
gonna
pass
it'll
no
longer
because
I
don't
need
to
do
anything
crazy
with
this
and
then
I
just
have
my
asserts
here.
So
I
say:
hey!
B
B
So
I
have
one
more
example
that
I'll
show
it's
the
same
function,
but
this
one's
a
little
bit
more
advanced,
because
in
this
case,
if
you
notice
from
this
attribute-
and
this
is
how
I
kind
of
set
up
those
relationships
with
other
services
here,
this
is
going
to
trigger
on
a
storage
queue.
Okay,
so
I'm
gonna
wait
for
a
message
to
get
dropped
in
a
storage
queue
and
I'm
gonna,
look
at
what
that
message
is
and
based
on
that
message.
B
There's
a
few
things
here:
I
need
to
know
if
it's
hot
or
even
but
I
also
want
to
make
an
outbound
call.
So
this
function
is
going
to
call.
You
can
see
a
very
important
API
and
I'm
gonna
pass
it
the
content,
whether
it's
odd
or
even
so,
there's
a
few
unique
things
about
this.
The
first
one
is,
you
know
this
is
potentially
a
more
rich
type.
This
might
be
something
like
a
a
cloud
queue
or
something
more
rich
than
string,
even
yeah.
A
B
It
also
gets
interesting
because
now
I
have
something
like
it
httpclient
and
how
do
I
make
sure
that
I
can
do
my
unit
test
in
the
same
way
where
I'm
not
injecting
this
httpclient?
This
is
just
something
in
my
function
right,
so
I'll
just
show
that
unit
test
to
a
lot
of
the
same
things
are
there
in
this
case,
though,
without
going
too
much
into
it,
and
all
this
code
is
on.
B
Github
will
actually
show
this
in
a
little
bit
I'm
going
to
mock
an
HTTP
request,
Handler
that
I'm
gonna
pass
in
as
that
HTTP
client.
So
here
I'm,
looking
at
that,
HTTP
client
that
I'm
going
to
be
using
I'm,
creating
a
mock
of
it,
so
that
when
I
send
it
a
request,
I
can
control
the
response,
so
I'm
not
actually
hitting
the
endpoint.
Yes,
I,
don't
want
to
actually
call
that
that
endpoint
and
do
something
important
whenever
I'm
running
my
unit
tests
so
I've
had
to
mock
this.
B
This
is
something
that's
a
little
bit
different
with
functions,
because
traditionally,
I
I
might
do
something
like
dependency
injection
sure
where
I
could
inject
in
my
own
client
handler.
But
here
because
we
don't
have
a
way
yet
it's
coming
soon.
We
don't
have
a
way
yet
to
do
full
dependency.
Injection
I've
actually
just
had
to
pull
that
actual
HTTP
client
and
change
it
before
I
run
any
of
my
tests
and
then
I
have
my
unit
tests
here
that
go
through
they
make
sure
if
it's
hot
or
even
I've
got
my.
A
One
of
the
ways
I
like
to
think
about
it
is
you
know,
even
as
even
though
agent
functions
is
a
is
a
service
platform,
we're
still
talking
about
testing
functions.
Yes
right,
it's
still
for
lack
of
better
words,
just
to
function,
yeah
right,
so
the
same
way
that
you
treat
your
your
typical
c-sharp
VB,
you
know
framework
functions.
This
is
something
that
we
could
look
at
this.
So
you
know
I
might
think.
Oh
hey,
I
have
this
trigger?
Oh,
my
god,
I
called
our
creator
trigger.
A
B
A
A
B
Like
this
is
something
totally
new
and
at
the
end
of
the
day,
to
your
point,
like
I,
just
have
a
you
know:
there
is
just
a
function
here
and
I
just
need
to
test
this
function
in
there.
I
guess
the
part
we
want
to
help
work
on
too
is
we
want
to
make
this
more
flexible?
In
fact,
you'll
see
some
stuff,
even
in
the
coming
weeks.
B
Yeah
we'll
let
you
do
some
more
things
with
dependency
injection
and
you
might
need
to
be
a
little
bit
more
creative,
where
we
don't
have
samples
as
much
and
making
sure
that
I
have
access
to
the
pieces.
I
need
to
manipulate
because,
as
we
said
at
the
beginning,
this
is
opinionated
as
well
like
I
can't
just
change
this
to
anything.
I
want
it
to
I
need
to
make
sure
I
have
this
attribute
has
to
be
a
set
number
of
types.
You
know,
ilogger
can't
be
any
logger,
it
needs
to
be
an
ilogger
and
so
forth.
B
B
Like
what
would
that
look
like
yeah?
This
is
a
that.
I
first
served
the
sound
get
hub
issue
because
everything
as
your
functions
is
actually
open
sourced
and
someone
was
like,
hey
I,
know
the
hosts
runtime.
The
thing
that's
actually
running
your
code,
the
thing
that
fires
this
trigger
I
know
that's
all
in
dotnet.
B
Is
there
a
way
that
is
part
of
my
testing
infrastructure
I
could
test
how
all
of
those
pieces
work
too,
because,
if
I
think
from
like
the
Pyramid
of
testing
these
unit
tests
are
great
and
I
can
do
a
bunch
of
them.
But
it's
really
just
testing
the
things
within
the
scope
of
line
15
to
line
38
here
right,
there's
a
whole
other
part
of
this
application,
where
this
is
going
to
get
hooked
into
the
functions.
Runtime,
it's
going
to
be
hooked
into
this
specific
queue.
B
I
need
to
make
sure
that
that
trigger
fires,
how
I
expect
it
to
that?
The
message
is
formatted.
How
I
expect
it
to,
and
that's
where
things
like
integration
testing
become
very
interesting,
because
I
want
to
make
sure
that
those
components
are
working
too
right.
I'm
not
gonna
do
them
at
the
same
scale.
I'm
not
gonna,
have
a
thousand
of
these
integration
tests,
but
I
do
want
a
small
few
to
make
sure
that
that
works
right.
B
So
there's
a
few
ways:
I've
seen
this
done
like
there's
the
kind
of
a
quick
and
dirty
way
which
is
just
I'm
gonna,
go
deploy
this
deploy
directly
into
the
cloud
and
I
can
just
run
a
few
tests
on
a
lying
on
a
developer
instance
of
my
function
and
then
it's
running
in
the
cloud
service
and
that
works
fine
too
right.
There
is
one
way,
though,
that
I'll
call
out
and
I've
used
this
before
in
a
few
samples.
B
I,
don't
have
it
for
this
test
project
right
now,
but
if
I
actually
come
to
like
our
as
your
functions
project.
So
this
is
the
github
project
for
where
we
write
as
your
functions,
where,
as
fully
open
source,
anybody
can
help
contribute,
but
we
actually
have
some
stuff
here
that
you
can
leverage
as
well.
B
So
if
I
come
into
our
tests,
we
run
integration
tests
on
a
number
of
different
functions
and
you
can
follow
the
same
patterns
that
we
do
as
well
for
how
we
do
things
like
integrate
testing
with
Kosmos
DB
in
a
great
testing
with
event
hubs,
and
all
of
it
really
comes
from
things
like
this
test
function
host.
So
here
and
you
could
use
this
same
code
and
I've
done
the
same
thing
where
I
like
copy
and
paste
this
code
into
my
own
test
projects.
B
I
can
actually
instantiate
my
own
version
of
the
azure
functions
host
in
memory
for
my
own
tests
right.
So
this
is
actually
like
going
and
creating
a
full
Azure
functions.
Runtime
it
we'll
go,
listen
to
the
services
that
it's
supposed
to
listen
to
it
will
trigger.
It
will
then
execute
my
code
and
I
can
then
validate
with
things
like
logs
and
and
metrics
to
make
sure
that
what
I
wanted
to
happen
actually
happen.
So
this
is
a
good
example
here.
B
I'm
not
gonna,
run
this
right
now,
but
the
same
way
that
we
do
these
integration
tests.
I
know
there's
a
lot
of
code
here,
because
we
test
a
lot
of
things
like
secrets
and
so
forth,
but
at
its
core,
like
I,
could
do
something
as
cool
as
I
open
up
my
test,
Explorer
say:
run
my
integration
test
and
completely
in
memory.
Whether
it's
an
azure
pipelines
are
here
in
Visual
Studio.
A
You
know,
and
one
of
the
things
I
like
to
tell
people
that
you
could
do
as
well
as
also
take
a
look
of
the
Azure
storage
emulator.
So
again,
if
you
wanted
a
you
know:
mock
storage
right,
for
whatever
reason
you
could
easily
do
that
right
so
on
you
can
install
it
on
your
machine.
It's
totally
free
right
and
then
know
you
can
point
your
your
your
functions.
Instance
to
that
right,
like
you're
your
host
instance
to
that,
and
so
now
you
can
have
like
a
mock
storage
so
to
speak.
A
B
B
Is
worth
calling
out?
It's
something
I
know
a
few
very
power
users
or,
following
these
examples,
to
run
these
integration
tests
to
have
that
extra
extra
bit
of
like
hey.
This
is
running
how
I
expect
it
to
and
again
something
that
that
we
want
to
make
even
more
accessible
as
we
move
forward.
So
just
keep
an
eye
on
this
repo
in
some
of
our
samples,
because
we'd
love
a
day
where,
like
I,
just
installed
a
new
get
package
into
my
you
know,
X
unit
or
MS,
test,
prot
or
exit.
B
A
B
A
Great
way
to
kind
of
just
get
feedback,
maybe
not
necessarily
integration
testing,
but
maybe
you
know,
testing
in
production
or
doing
some
a
be
testing.
You
know
you
can
have
different
versions
of
your
functions
and
it's
running
inside
of
the
cloud
and
I
can
kind
of
look
at
some
of
that
telemetry
and
I
think
and
understand,
like
what
exactly
is
happening
here
on
which
version
and
you
know
like
what
are
you
know,
what
are
my
results
on
either
side
of
the
table
so.
B
That's
another
thing
too:
I
think
we
could
point
out.
It
is
and
the
like
there's
a
few
things
in
that
too
I
think
one
of
the
nice
things
about
serverless.
Is
you
really
can
just
kind
of
publish
this
app
like
the
one
I
have
right
now
up
into
the
cloud
you
know
and
run
whatever
tests.
I
want
look
at
the
telemetry
from
app
insights
and
do
some
tests
there
without
having
to
worry
about
necessarily
doing
it
all
emulated,
because
it's
all
serverless
like
I'm,
not
paying
for
unless
I'm
running
it.
B
It's
not
gonna
have
to
worry
about.
Like
oh
now,
I
have
to
pay
for
two
copies
of
my
production
environment.
It's
like
you're,
only
really
paying
for
the
tests
you're
running.
No.
The
other
interesting
thing
too,
though,
is
you
can
even
run
some
of
these
tests
that
we've
been
talking
about,
because
this
is
fully
open
sourced
you
could,
if
you
wanted
to,
you,
could
run
some
of
these
tests
unit
test
integration
tests
on
the
version
of
azure
functions
that
we
haven't
yet
rolled
out
to
the
cloud
service.
B
A
A
Sure,
absolutely
that's
awesome,
and
so
now
what?
If
I
you
know,
I
needed
to
go
somewhere
to
get
some
resources?
Well,
harken
I
can
get
started
with
this,
like
I
want
to
learn
how
to
test
this
I
want
to
I
want
to
see
some
samples
of
some
demos,
or
maybe
even
I,
want
to
reach
out
to
the
team,
and
you
know
contact
somebody
about.
Am
I
doing
this
the
right
way
like
what
is
what
is
the
path
that
I
need
to
go
down
for
that
yeah.
B
And
this
is
still
like
it's
even
apparent
from
this,
like
this
is
still
an
evolving
space
like
there's.
We
want
to
hear
as
much
from
the
community
as
we
want
to
talk
to
the
community
on
like
what
are
some
of
the
ways
that
you
want
to
be
able
to
test
your
functions.
What
are
some
of
the
things
we're
missing
in
terms
of
the
best
places
to
get
started?
There's
a
few
that
are
helpful.
B
There
is
a
blog
series
on
the
Microsoft
Azure
medium
blog,
that
I
test
that
I
wrote
that
has
to
do
with
serverless
and
DevOps
and
CIC
dei
I
talked
about
unit
testing.
I
go
through
some
of
these
samples,
I
even
go
into
things
like
making
that
an
automated
release
process.
So
that's
something
worth
looking
at.
Have
you
go
and
subscribe
to
the
Microsoft
Azure
blog
on
medium
as
a
whole,
our
team
we're
very
active
on
things
like
github.
B
That's
right
so,
every
month
on,
YouTube
there's
an
azure
functions,
YouTube
channel.
If
you
subscribe
to
that
once
a
month,
we'll
go
out
we'll
we'll
talk
about
some
of
those
things,
we're
working
on
some
of
the
things
we've
shipped
and
then
answer
questions.
That's
another
good
resource
as
well.
Cool.