Slide 1

Slide 1 text

android Clean Code Mohanraj Karatadipalayam @kmmraj

Slide 2

Slide 2 text

Let's Start With Unit Testing • Typical Activity Class • Data retrieval • Data manipulation and decoration • UI-specific activities like rendering, painting, responding to user events, and the creation of fragments. • One class does all work • Massive Activity, Massive Fragment, Massive ViewController

Slide 3

Slide 3 text

Can I Test them ? • Lets take data retrieval • All methods are intertwined • Doing everything everywhere • I need API provider • I need SQLite • I need to convert from datamodel to viewmodel • Mocking cannot rescue

Slide 4

Slide 4 text

Does your App Architecture supports unit testing ? • Search for the testing tools • Forgetting the need

Slide 5

Slide 5 text

Where to start ? • Clean architecture • VIPER • Force fitting in to Android • clean-swift

Slide 6

Slide 6 text

Android Clean Code

Slide 7

Slide 7 text

Lets spilt the Monolithic Activity • Retrieve the data • Modify the model data according to viewmodel needs • Handle UI specific work • How they talk to each other ? • Interfaces • Unidirectional Flow

Slide 8

Slide 8 text

Activity

Slide 9

Slide 9 text

Activity Unit Testing • Using Roboletric to simulate the Activity • Canary test • How do we test the Activity without Interactor?

Slide 10

Slide 10 text

Activity Unit Testing

Slide 11

Slide 11 text

Activity Unit Testing

Slide 12

Slide 12 text

Interactor • Interactor retrieves the data from data sources like the local DB, web service, and content provider.

Slide 13

Slide 13 text

Why we need Worker ? • If the task is simpler- No need • If you foresee that the task can be reused somewhere else in the app, move it to the Worker.

Slide 14

Slide 14 text

Testing Interactor • How to test Interactor with out Worker & Presenter

Slide 15

Slide 15 text

Testing Interactor

Slide 16

Slide 16 text

Presenter • Reduce the Model to VM

Slide 17

Slide 17 text

Presenter

Slide 18

Slide 18 text

Testing Presenter • FIRST • Fast • Isolated • Repeatable • Self-Validating • Timely

Slide 19

Slide 19 text

Router • Determines the next screen • Pass the needed data to the next screen

Slide 20

Slide 20 text

Testing Router

Slide 21

Slide 21 text

Configurator

Slide 22

Slide 22 text

Scaffolding

Slide 23

Slide 23 text

What’s next? • Predictability • Developers can work across the technologies • Contribute • Refine