2. UNIT
TESTS
ARE
NOT
ABOUT
FINDING
BUGS
…so
what
they
are
about?
hCp://www.flickr.com/photos/rupert_brun/6658715247
3. BOTTOM-‐UP
vs.
OUTSIDE-‐IN
There
are
two
styles
of
wriXng
programs
4. BOTTOM-‐UP
You
can
write
program
starXng
with
the
low-‐level
code
5. BOTTOM-‐UP
E.g.
you
start
with
database
and
data
access
code
and
conXnue
up
to
the
UI
UI
Controllers
Domain
Model
Data
Access
DB
Schema
6. OUTSIDE-‐IN
Or
you
can
start
with
UI
or
some
business
logic,
postponing
the
low-‐level
details
unXl
really
necessary…
7. OUTSIDE-‐IN
…because
the
low-‐
level
details
have
no
business
value
hCp://indeb^atshortbadteeth.wordpress.com/2012/01/20/hello-‐goals-‐for-‐a-‐fortnight-‐thursday-‐results-‐for-‐challenge-‐1-‐and-‐new-‐goal/
8. OUTSIDE-‐IN
When
wriXng
program
outside-‐in,
you
need
to
replace
the
low-‐level
code
with
mocks
–
it
was
not
wriCen
yet
See
the
video
recording
for
demo
how
to
do
it
9. So
we
have
seen
in
demo
how
to
write
program
from
tests
and
we
may
now
understand
that…
UNIT
TESTS
ARE
NOT
(just)
ABOUT
FINDING
BUGS
…but
why?
And
what
they
are
about?
hCp://www.flickr.com/photos/rupert_brun/6658715247
10. EXTERNAL
QUALITY
vs.
INTERNAL
QUALITY
First,
we
need
to
have
a
look
at
two
kinds
of
quality
in
computer
sofware
11. EXTERNAL
QUALITY
how
well
the
system
meets
the
needs
of
its
customers
and
users
(is
it
funcXonal,
reliable,
available,
responsive...)
hCp://www.youtube.com/watch?v=SLikJ1c53wc
12. INTERNAL
QUALITY
how
well
it
meets
the
needs
of
its
developers
and
administrators
(is
it
easy
to
understand,
easy
to
change...)
13. UNIT
TEST
Test
Unit
test
execute
the
object
in
isolaXon,
mocking
all
dependencies…
…but
what
can
this
test
tell
us
about
external
quality?
14. Of
course
nothing!
USER
Because
users
execute
the
applicaXon
like
this:
User
And
this
is
how
end-‐
to-‐end
test
works.
16. …and
it
contains
this
charts,
explaining
what
kind
of
feedback
is
provided
by
different
kinds
of
Unit
test
tells
us
a
lot
tests
about
the
internal
quality
of
the
code…
…while
end-‐to-‐end
test
provides
a
lot
of
feedback
about
the
external
quality
of
the
app
17. Which
means
that…
UNIT
TESTS
ARE
NOT
ABOUT
FINDING
BUGS
…because…
hCp://www.flickr.com/photos/rupert_brun/6658715247
18. UNIT
TESTS
ARE
DESIGN
TOOL
…that
helps
keeping
the
code
clean
and
maintainable
hCp://www.flickr.com/photos/shelfappeal/4531230129
20. HARD
TO
TEST
=
BADLY
DESIGNED
…because
the
unit
tests
tell
us
a
lot
about
internal
quality
of
the
code
21. Therefore,
if
you
want
to
write
unit
tests…
FIX
CODE
FIRST!
Otherwise
you
will
spend
ages
wriXng
terrible,
ugly
and
long
unit
tests,
just
to
find
out
that
the
internal
quality
of
the
code
is
bad
22. It
makes
no
sense
to
unit
test
this:
…without
trying
to
improve
the
internal
design
hCp://www.flickr.com/photos/daveparker/28335459
23. Odkazy
k
přednášce
najdete
na
hCp://blog.kolman.cz
Because…
UNIT
TESTS
ARE
DESIGN
TOOL
Thank
you!
Daniel
Kolman
@kolman
blog.kolman.cz
www.vendavo.cz