Slide 1

Slide 1 text

Take a stab at test friendly architecture Brian Gardner

Slide 2

Slide 2 text

Goals ● Principles & Patterns ● Where DI can help ● Testing setup

Slide 3

Slide 3 text

Quick Pit Stop

Slide 4

Slide 4 text

Sample Application

Slide 5

Slide 5 text

List Screen Dependencies

Slide 6

Slide 6 text

Create Screen Dependencies

Slide 7

Slide 7 text

Cleaner Architecture Patterns

Slide 8

Slide 8 text

Single Responsibility Principle

Slide 9

Slide 9 text

Do one thing and do it well

Slide 10

Slide 10 text

Smaller api == smaller tests

Slide 11

Slide 11 text

UI Architecture Selection ● MVC ● MVP ● MVVM ● VIPER

Slide 12

Slide 12 text

Sample Architecture

Slide 13

Slide 13 text

Bias Towards Interfaces Composition vs Inheritance What it does vs. what it is

Slide 14

Slide 14 text

Example Refactor

Slide 15

Slide 15 text

Finding an interface instead of using a concrete class helps with testing

Slide 16

Slide 16 text

Explicit Dependencies

Slide 17

Slide 17 text

Implicit Dependencies

Slide 18

Slide 18 text

Implicit Dependencies

Slide 19

Slide 19 text

Explicit Dependencies

Slide 20

Slide 20 text

Recap ● SRP ● UI Architecture ● Bias Towards Interfaces ● Explicit Dependencies

Slide 21

Slide 21 text

Dependency Injection

Slide 22

Slide 22 text

Dagger Recap

Slide 23

Slide 23 text

Dagger Recap

Slide 24

Slide 24 text

Dagger recap

Slide 25

Slide 25 text

Dagger recap

Slide 26

Slide 26 text

Applying the tools

Slide 27

Slide 27 text

Single Responsibility Principle

Slide 28

Slide 28 text

Doesn’t really help here

Slide 29

Slide 29 text

Apply SRP to Dependency Injection

Slide 30

Slide 30 text

Apply SRP to Dependency Injection

Slide 31

Slide 31 text

UI Architecture Patterns

Slide 32

Slide 32 text

Also doesn’t really help

Slide 33

Slide 33 text

Bias Towards Interfaces

Slide 34

Slide 34 text

Injecting Interfaces

Slide 35

Slide 35 text

Different Interface Injection

Slide 36

Slide 36 text

Explicit Dependencies

Slide 37

Slide 37 text

Perfect Tool For The Job

Slide 38

Slide 38 text

Perfect Tool For The Job

Slide 39

Slide 39 text

Recap 2 ● Use SRP on injection code ● Not relevant for UI architecture ● Flexible for providing interfaces ● Perfect for explicit dependencies

Slide 40

Slide 40 text

Testing Time!

Slide 41

Slide 41 text

Unit Testing

Slide 42

Slide 42 text

Don’t use it for unit testing

Slide 43

Slide 43 text

Remember This?

Slide 44

Slide 44 text

Remember This?

Slide 45

Slide 45 text

No Need For DI

Slide 46

Slide 46 text

Integration Testing

Slide 47

Slide 47 text

Fakes?

Slide 48

Slide 48 text

Module For Fake

Slide 49

Slide 49 text

Test Component

Slide 50

Slide 50 text

Test Application

Slide 51

Slide 51 text

Custom Test Runner

Slide 52

Slide 52 text

Supply Test Application

Slide 53

Slide 53 text

Using Custom Test Runner

Slide 54

Slide 54 text

Example Integration Test

Slide 55

Slide 55 text

Small issue

Slide 56

Slide 56 text

Unused Test Runner

Slide 57

Slide 57 text

What About Robolectric?

Slide 58

Slide 58 text

Custom Robolectric Application

Slide 59

Slide 59 text

Conclusion

Slide 60

Slide 60 text

Who is this guy? Brian Gardner @bgardner7 Big Nerd Ranch We Teach, We Develop, We Write