Slide 1

Slide 1 text

CONFIDENTIAL & RESTRICTED Mohanraj Karatadipalayam https://medium.com/@kmmraj

Slide 2

Slide 2 text

CONFIDENTIAL & RESTRICTED PROBLEM Vs A B Incremental Changes Disruptive Changes

Slide 3

Slide 3 text

CONFIDENTIAL & RESTRICTED HOW DO WE REACT? Tools Process Testing Designs

Slide 4

Slide 4 text

CONFIDENTIAL & RESTRICTED Receptive to unit testing? Tools support Uses minimal mocking / no mocking at all Soup ? WHAT ABOUT APP ARCHITECTURE?

Slide 5

Slide 5 text

CONFIDENTIAL & RESTRICTED UNIT TESTING OF APPS UNIT TESTING OF APPS Trivial ? Code coverage ? How much we test ?

Slide 6

Slide 6 text

CONFIDENTIAL & RESTRICTED LET US START WITH UNIT TESTING o Functions are doing everything everywhere o Intertwined o Testing them ? o Mock it ?

Slide 7

Slide 7 text

CONFIDENTIAL & RESTRICTED PERFECT UNIT TESTING FRAMEWORK • jUnit • Roboletric • fragment-testing androidx

Slide 8

Slide 8 text

CONFIDENTIAL & RESTRICTED “One of the major reasons behind the failure of the unit test automation is an architecture of the app that does not support unit testing.”

Slide 9

Slide 9 text

CONFIDENTIAL & RESTRICTED My Journey of finding a unit testable architecture

Slide 10

Slide 10 text

CONFIDENTIAL & RESTRICTED Android code has a massive activity or fragment Typical fragment class do the below tasks Data retrieval from data sources Data manipulation and decoration UI Specific activities Life cycle UNIT TESTING IN APPS

Slide 11

Slide 11 text

CONFIDENTIAL & RESTRICTED

Slide 12

Slide 12 text

CONFIDENTIAL & RESTRICTED Native Mobile Development Patterns • MVMM • MVP • VIPER – View Interactor Presenter Entity Route • Clean Swift

Slide 13

Slide 13 text

CONFIDENTIAL & RESTRICTED CLEAN SWIFT à CLEAN KOTLIN FOR ANDROID

Slide 14

Slide 14 text

CONFIDENTIAL & RESTRICTED

Slide 15

Slide 15 text

CONFIDENTIAL & RESTRICTED LET’S SPLIT IT UP 1 Get data from one or more data source à Interactor 2 Modify data in form that can be presented by the fragment à Presenter 3 Present data and listen to user events à Fragment

Slide 16

Slide 16 text

CONFIDENTIAL & RESTRICTED Clean Kotlin - Incubation Uni - directional

Slide 17

Slide 17 text

CONFIDENTIAL & RESTRICTED How they talk to each other Interfaces

Slide 18

Slide 18 text

CONFIDENTIAL & RESTRICTED WHY INTERFACES? MOCK FAKE SPY

Slide 19

Slide 19 text

CONFIDENTIAL & RESTRICTED LET’S GET STARTED

Slide 20

Slide 20 text

CONFIDENTIAL & RESTRICTED CONFIGURATOR Does the wiring of the dependencies Worried about writing too many boilerplate codes?

Slide 21

Slide 21 text

CONFIDENTIAL & RESTRICTED • Smoke test • how do we test the fragment without Interactor? LET’S TEST IT

Slide 22

Slide 22 text

CONFIDENTIAL & RESTRICTED MORE TESTING

Slide 23

Slide 23 text

CONFIDENTIAL & RESTRICTED • What is the work of Interactor? • data from the data sources like local DB, web service and content provider INTERACTOR

Slide 24

Slide 24 text

CONFIDENTIAL & RESTRICTED INTERACTOR CODE

Slide 25

Slide 25 text

CONFIDENTIAL & RESTRICTED • If the task is simpler, you can have all the work done by the Interactor itself. • When you foresee that the task can be reused somewhere else in the app, move it to the worker. WHAT IS THE NEED FOR THE WORKER?

Slide 26

Slide 26 text

CONFIDENTIAL & RESTRICTED • Call back Hell ? • Use Rx | Kotlin Co routines WORKER

Slide 27

Slide 27 text

CONFIDENTIAL & RESTRICTED • We don’t need a real worker, let’s create a spy. • And Spy for presenter INTERACTOR UNIT TESTING

Slide 28

Slide 28 text

CONFIDENTIAL & RESTRICTED UNIT TEST IT — PIECE BY PIECE

Slide 29

Slide 29 text

CONFIDENTIAL & RESTRICTED What is the work of Presenter? PRESENTER

Slide 30

Slide 30 text

CONFIDENTIAL & RESTRICTED • Date of travel is in the YYYY/MM/DD PRESENTER

Slide 31

Slide 31 text

CONFIDENTIAL & RESTRICTED PRESENTER

Slide 32

Slide 32 text

CONFIDENTIAL & RESTRICTED • As usual -- Mock or Spy? PRESENTER UNIT TESTING

Slide 33

Slide 33 text

CONFIDENTIAL & RESTRICTED PRESENTER UNIT TESTING

Slide 34

Slide 34 text

CONFIDENTIAL & RESTRICTED ROUTER https://medium.com/@kmmraj

Slide 35

Slide 35 text

CONFIDENTIAL & RESTRICTED ROUTER https://medium.com/@kmmraj

Slide 36

Slide 36 text

CONFIDENTIAL & RESTRICTED UNIT TESTING ROUTER https://medium.com/@kmmraj

Slide 37

Slide 37 text

CONFIDENTIAL & RESTRICTED CONFIGURATOR https://medium.com/@kmmraj

Slide 38

Slide 38 text

CONFIDENTIAL & RESTRICTED TOO MUCH BOILERPLATE CODE? https://medium.com/@kmmraj

Slide 39

Slide 39 text

CONFIDENTIAL & RESTRICTED References • https://medium.com/@kmmraj/kotlin-clean-code-for-android-series- f3b32307342d • http://bit.ly/KtlnCC4Drd • https://github.com/kmmraj/kt-clean-code4Android-generator • https://github.com/kmmraj/KotlinCleanCode4Android • https://clean-swift.com/ https://medium.com/@kmmraj