CYA:
Cover Your App
Jorge D. Ortiz Fuentes
@jdortiz
A Canonical
Examples
Production
#AdvArchMobile
Agenda
★ Motivation
★ Facts
★ What’s missing?
★ Architecture
★ Live Coding
★ Recap
Motivation
But my code is
always awesome!
#AdvArchMobile
Selfish Unit Tests
★ No more discussions
★ No more explanations to the team
★ No more questions
★ No more bugs introduced by them
★ No more missed deadlines
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ No more explanations to the team
★ No more questions
★ No more bugs introduced by them
★ No more missed deadlines
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ No more questions
★ No more bugs introduced by them
★ No more missed deadlines
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Document the code
★ No more bugs introduced by them
★ No more missed deadlines
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Document the code
★ Easier refactoring or change
★ No more missed deadlines
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Document the code
★ Easier refactoring or change
★ Better estimations for tests than debug
★ No more late hours
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Document the code
★ Easier refactoring or change
★ Better estimations for tests than debug
★ Reusable code = code + tests
Prove correctness of
different aspects of
the public interface
Test the parts that
you aren’t
developing now
Facts
Coverage
=
Measurement
We want:
“Code is proven
correct in all cases”
We get:
“Lines used by the
tests”
Demo:
Demystifying
Coverage
#AdvArchMobile
What you have seen
★ Full CRUD
★ 100% Kotlin (everything but generated
code)
★ Mockito + Mockito-Kotlin
★ Good architecture
★ TDD
What is
Missing?
#AdvArchMobile
Not Covered
★ Dagger factories
★ Platform: implementation details (activities,
adapters, application subclass, DI)
Let’s do better
Architecture
MVP
ViewPresenterModel
display commands
events
fetch/change

data
Test View Methods
ViewPresenterModel
display commands
events
fetch/change

data
Test Events To Presenter
ViewPresenterModel
display commands
events
fetch/change

data
Presenter
#AdvArchMobile
How to Mock the
Presenter
★ App uses Dagger 2 for DI
★ Dagger 2 is NOT meant for Unit Testing
★ Activities use Service Locator for DI
★ Service Locator abstraction is implemented
by Application subclass
★ Unit tests use another Application subclass
And if I am an
MVVM Person?
Live Coding
Let’s write this
together
#AdvArchMobile
Recap
★ Unit Tests are good for you (and for others)
★ Code coverage is not the best metric
★ Good coverage is better
★ A good architecture will help to cover the
different aspects of your
Thank
You!
@jdortiz
#AdvArchMobile

CYA: Cover Your App