cya: cover your app
TRANSCRIPT
![Page 1: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/1.jpg)
CYA: Cover Your App
Jorge D. Ortiz Fuentes @jdortiz
![Page 2: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/2.jpg)
A Canonical Examples Production
![Page 3: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/3.jpg)
#AdvArchMobile
Agenda★Motivation
★ Facts
★What’s missing?
★Architecture
★ Live Coding
★Recap
![Page 4: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/4.jpg)
Motivation
![Page 5: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/5.jpg)
But my code is always awesome!
![Page 6: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/6.jpg)
#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
![Page 7: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/7.jpg)
#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
![Page 8: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/8.jpg)
#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
![Page 9: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/9.jpg)
#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
![Page 10: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/10.jpg)
#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
![Page 11: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/11.jpg)
#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
![Page 12: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/12.jpg)
#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
![Page 13: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/13.jpg)
Prove correctness of different aspects of the public interface
![Page 14: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/14.jpg)
Test the parts that you aren’t
developing now
![Page 15: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/15.jpg)
Facts
![Page 16: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/16.jpg)
Coverage =
Measurement
![Page 17: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/17.jpg)
We want: “Code is proven
correct in all cases”
![Page 18: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/18.jpg)
We get: “Lines used by the
tests”
![Page 19: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/19.jpg)
Demo: Demystifying
Coverage
![Page 20: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/20.jpg)
#AdvArchMobile
What you have seen★ Full CRUD
★100% Kotlin (everything but generated code)
★Mockito + Mockito-Kotlin
★Good architecture
★TDD
![Page 21: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/21.jpg)
What is Missing?
![Page 22: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/22.jpg)
#AdvArchMobile
Not Covered
★Dagger factories
★Platform: implementation details (activities, adapters, application subclass, DI)
![Page 23: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/23.jpg)
Let’s do better
![Page 24: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/24.jpg)
Architecture
![Page 25: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/25.jpg)
MVP
ViewPresenterModel
display commands
events
fetch/changedata
![Page 26: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/26.jpg)
Test View Methods
ViewPresenterModel
display commands
events
fetch/changedata
![Page 27: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/27.jpg)
Test Events To Presenter
ViewPresenterModel
display commands
events
fetch/changedata
Presenter
![Page 28: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/28.jpg)
#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
![Page 29: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/29.jpg)
And if I am an MVVM Person?
![Page 30: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/30.jpg)
Live Coding
![Page 31: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/31.jpg)
Let’s write this together
![Page 32: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/32.jpg)
#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
![Page 33: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/33.jpg)
Thank You!
![Page 34: CYA: Cover Your App](https://reader034.vdocuments.us/reader034/viewer/2022051503/5a66fc737f8b9a68588b492b/html5/thumbnails/34.jpg)
@jdortiz #AdvArchMobile