Slide 1

Slide 1 text

How ANDROID TESTING changed how we think about death… @fernando_cejas Code samples: https://github.com/android10/Inside_Android_Testing https://github.com/android10/AndroidApplicationTestingSample

Slide 2

Slide 2 text

Who am I… •  Software Engineer •  GDG Barcelona Organizer •  Android lover •  Geek •  Gintonic fan… …y un pelotudo…

Slide 3

Slide 3 text

Agenda?

Slide 4

Slide 4 text

Why testing..WTF? •  Testing increases the level of confidence in your code. •  Testing makes it possible to write new code, and refactor existing code, without worrying that you’ve broken existing functionality.

Slide 5

Slide 5 text

Martin Fowler: "...test-doubles ... preprogrammed with expectation" What is this mock thing?

Slide 6

Slide 6 text

Mockito is a mocking framework that tastes really good. Mockito doesn't give you hangover because the tests are very readable and they produce clean verification errors. GIVE A WARM WELCOME TO… mockito

Slide 7

Slide 7 text

Mockito Build-operate-check pattern

Slide 8

Slide 8 text

Mock initizalition

Slide 9

Slide 9 text

Initizalition using mockito test runner

Slide 10

Slide 10 text

Let’s verify some behaviour

Slide 11

Slide 11 text

Argument matchers

Slide 12

Slide 12 text

Verifying number of invocations / at least x / never

Slide 13

Slide 13 text

Making sure interaction(s) never happened on mock

Slide 14

Slide 14 text

Spying on real objects

Slide 15

Slide 15 text

Sounds familiar???

Slide 16

Slide 16 text

Allows you to run your android code on JVM. Allows loading of Android Classes in pure Java Projects. TO THE RESCUE…

Slide 17

Slide 17 text

Shadow Objects!

Slide 18

Slide 18 text

View and Resource Loading…

Slide 19

Slide 19 text

Shadow Activity Shadow ImageView

Slide 20

Slide 20 text

•  Uses real Android SDK code •  Styles and themes supported •  System resources are available •  Performance improved •  Bugs fixed Robolectric 2.0+

Slide 21

Slide 21 text

Perform click Sample

Slide 22

Slide 22 text

Started Activity test Should have fragment test

Slide 23

Slide 23 text

Device Configuration Sample

Slide 24

Slide 24 text

Network sample Robolectric acts as a proxy!!!

Slide 25

Slide 25 text

Creating your own shadows

Slide 26

Slide 26 text

Creating your own shadows

Slide 27

Slide 27 text

Creating your own shadows

Slide 28

Slide 28 text

•  A library by square (FTW!) •  It gives a chainable (or “fluent”) syntax for checking assertions. •  Makes tests easier to write (and read!). FEST Android

Slide 29

Slide 29 text

Sample: code to modify a bitmap

Slide 30

Slide 30 text

Assertions with FEST

Slide 31

Slide 31 text

Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time Dependency what?

Slide 32

Slide 32 text

Dagger Directed Acyclic Graph

Slide 33

Slide 33 text

Dagger Graph sample

Slide 34

Slide 34 text

Dagger sample

Slide 35

Slide 35 text

Declare dependencies

Slide 36

Slide 36 text

Satisfy dependencies

Slide 37

Slide 37 text

Build the graph

Slide 38

Slide 38 text

Modules

Slide 39

Slide 39 text

Spoon •  Acceptance tests (black box) •  Automation of test execution across multiple devices •  Aggregation of the results

Slide 40

Slide 40 text

Spoon •  Aggregation of screenshots while your tests are running

Slide 41

Slide 41 text

•  Robojuice •  Robotium •  Android Testing Framework •  UI Automator •  Monkey Runner More tools…

Slide 42

Slide 42 text

WRITE TESTS!!! •  Simplify your architecture •  Have a robust testing strategy •  Use continuous integration tools •  Mock/stub functionality •  Create your own test runner Best practices and some advice…

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Questions?

Slide 45

Slide 45 text

@fernando_cejas https://github.com/android10 [email protected] http://corporate.tuenti.com/es/dev/blog THANKS!!!