cya: cover your app

34
CYA: Cover Your App Jorge D. Ortiz Fuentes @jdortiz

Upload: jorge-ortiz

Post on 23-Jan-2018

61 views

Category:

Software


2 download

TRANSCRIPT

Page 1: CYA: Cover Your App

CYA: Cover Your App

Jorge D. Ortiz Fuentes @jdortiz

Page 2: CYA: Cover Your App

A Canonical Examples Production

Page 3: CYA: Cover Your App

#AdvArchMobile

Agenda★Motivation

★ Facts

★What’s missing?

★Architecture

★ Live Coding

★Recap

Page 4: CYA: Cover Your App

Motivation

Page 5: CYA: Cover Your App

But my code is always awesome!

Page 6: CYA: Cover Your App

#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

#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

#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

#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

#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

#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

#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

Prove correctness of different aspects of the public interface

Page 14: CYA: Cover Your App

Test the parts that you aren’t

developing now

Page 15: CYA: Cover Your App

Facts

Page 16: CYA: Cover Your App

Coverage =

Measurement

Page 17: CYA: Cover Your App

We want: “Code is proven

correct in all cases”

Page 18: CYA: Cover Your App

We get: “Lines used by the

tests”

Page 19: CYA: Cover Your App

Demo: Demystifying

Coverage

Page 20: CYA: Cover Your App

#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

What is Missing?

Page 22: CYA: Cover Your App

#AdvArchMobile

Not Covered

★Dagger factories

★Platform: implementation details (activities, adapters, application subclass, DI)

Page 23: CYA: Cover Your App

Let’s do better

Page 24: CYA: Cover Your App

Architecture

Page 25: CYA: Cover Your App

MVP

ViewPresenterModel

display commands

events

fetch/changedata

Page 26: CYA: Cover Your App

Test View Methods

ViewPresenterModel

display commands

events

fetch/changedata

Page 27: CYA: Cover Your App

Test Events To Presenter

ViewPresenterModel

display commands

events

fetch/changedata

Presenter

Page 28: CYA: Cover Your App

#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

And if I am an MVVM Person?

Page 30: CYA: Cover Your App

Live Coding

Page 31: CYA: Cover Your App

Let’s write this together

Page 32: CYA: Cover Your App

#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

Thank You!

Page 34: CYA: Cover Your App

@jdortiz #AdvArchMobile