Slide 1

Slide 1 text

Testable Android Architecture 29 Sept 2016 / Chuck Greb

Slide 2

Slide 2 text

Clean code Software Craftsmanship

Slide 3

Slide 3 text

Art is anything you can do well. Anything you can do with Quality. “ ” - Robert M. Pirsig

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Clean Architecture MVC <> MVP <> MVVM

Slide 6

Slide 6 text

In the beginning

Slide 7

Slide 7 text

Activity

Slide 8

Slide 8 text

Activity Activity Lifecycle System Services

Slide 9

Slide 9 text

Activity EditText Button Activity Lifecycle System Services

Slide 10

Slide 10 text

Activity EditText Button Web Service Storage AsyncTask Activity Lifecycle System Services

Slide 11

Slide 11 text

Fragment Activity EditText Button Web Service Storage AsyncTask Activity Lifecycle System Services Fragment Fragment Lifecycle

Slide 12

Slide 12 text

Fragment Activity EditText Button Web Service Storage AsyncTask Activity Lifecycle System Services Fragment Fragment Lifecycle User Input Input Validation

Slide 13

Slide 13 text

Fragment Activity Web Service Storage AsyncTask Activity Lifecycle System Services Fragment Fragment Lifecycle User Input setRetainInstance(true) EditText Button Input Validation

Slide 14

Slide 14 text

Fragment Activity Web Service Storage AsyncTask Activity Lifecycle System Services Fragment Fragment Lifecycle User Input setRetainInstance(true) Intent Parcelable Extras EditText Button Input Validation

Slide 15

Slide 15 text

Web Service Storage Activity Fragment Fragment AsyncTask setRetainInstance(true) Activity Lifecycle Fragment Lifecycle System Services User Input Intent ActivityInstrumentati onTestCase2 Parcelable Extras EditText Button Input Validation

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

There has to be a better way

Slide 18

Slide 18 text

Activity Logic

Slide 19

Slide 19 text

Activity Logic Data

Slide 20

Slide 20 text

Activity Logic Data View

Slide 21

Slide 21 text

View (Activity) Controller (Logic) Model (Data) View

Slide 22

Slide 22 text

View (Activity) Presenter (Logic) Model (Data) View

Slide 23

Slide 23 text

View (Activity) ViewModel (Logic) Model (Data) View

Slide 24

Slide 24 text

Controller (Activity) Subcontroller (Logic) Model (Data) View

Slide 25

Slide 25 text

- Phil Karlton There are two hard things in computer science: cache invalidation, naming things, [and errors off by one.] “ ”

Slide 26

Slide 26 text

Clean Architecture Model View Presenter Controller MVP(C)

Slide 27

Slide 27 text

Controller (Activity) Presenter (Logic) Model (Data) View

Slide 28

Slide 28 text

Activity Presenter (Logic) Model (Data) View Controller

Slide 29

Slide 29 text

Web Service Storage Activity Activity Lifecycle System Services User Input Presenter View Model Controller Button EditText Thread Input Validation

Slide 30

Slide 30 text

Web Service Storage Activity Activity Lifecycle System Services User Input Presenter View Model Controller Thread Button EditText Input Validation

Slide 31

Slide 31 text

Mock Service Mock Storage Test Controller Presenter Model Controller Thread JUnit TestRunner

Slide 32

Slide 32 text

A test is not a unit test if: → It talks to the database → It communicates across the network → It touches the file system → It can't run at the same time as any of your other unit tests → You have to do special things to your environment (such as editing config files) to run it. Michael Feathers, 2005 A Set of Unit Test Rules

Slide 33

Slide 33 text

Mock Service Mock Storage Test Controller Presenter Model Controller Thread JUnit TestRunner

Slide 34

Slide 34 text

Activity Robolectric TestRunner Robolectric Runtime Environment Simulated Input Stub Presenter View Button EditText Input Validation

Slide 35

Slide 35 text

Demo App https://github.com/ecgreb/mvpc

Slide 36

Slide 36 text

Eraser Map

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Start where you are