Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 b...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ No more explanations to the team
★ No ...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ No m...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Docu...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Docu...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Docu...
#AdvArchMobile
Selfish Unit Tests
★ Prove (to others) instead of (your) intuition
★ Define contract and assumptions
★ Docu...
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
★ G...
What is
Missing?
#AdvArchMobile
Not Covered
★ Dagger factories
★ Platform: implementation details (activities,
adapters, application subcla...
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 ...
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...
Thank
You!
@jdortiz
#AdvArchMobile
Upcoming SlideShare
Loading in …5
×

CYA: Cover Your App

126 views

Published on

Talk at Droidcon London 2017

Testing is a fundamental component for the success of our apps. Professionals in charge for developing Android apps are well aware of that and we are doing our best to add unit tests to our apps. But having a good test coverage is not an easy task. More so, when activities (or fragments) get in the middle.

In this talk, I shared a brief introduction about how architecture helps us to increase code coverage and provided some practical hints.

I did do some live coding to show how to use espresso and JUnit to write unit tests of an activity. The code was written in Kotlin, but the same can easily be done in Java.

The video of this talk is here: (requires free subscription)
https://skillsmatter.com/skillscasts/10534-cya-cover-your-app

Published in: Software
  • Be the first to comment

  • Be the first to like this

CYA: Cover Your App

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

×