how android testing changed how we think about death

45
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

Upload: fernando-cejas

Post on 06-May-2015

614 views

Category:

Technology


3 download

DESCRIPTION

"Irreproducible bugs become highly reproducible right after delivery to the customer". This is something that happens "almost" everyday. It is well known that testing offers significant advantages as a development practice and helps ensure higher quality code with fewer defects. Unfortunately, testing Android apps can be challenging, so in this session we are gonna talk about available tools and practices that could help us accomplish our goals.

TRANSCRIPT

Page 1: How ANDROID TESTING changed how we think about Death

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

Page 2: How ANDROID TESTING changed how we think about Death

Who am I…

•  Software Engineer •  GDG Barcelona Organizer •  Android lover •  Geek •  Gintonic fan…

…y un pelotudo…

Page 3: How ANDROID TESTING changed how we think about Death

Agenda?

Page 4: How ANDROID TESTING changed how we think about Death

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.

Page 5: How ANDROID TESTING changed how we think about Death

Martin Fowler: "...test-doubles ... preprogrammed with

expectation"

What is this mock thing?

Page 6: How ANDROID TESTING changed how we think about Death

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

Page 7: How ANDROID TESTING changed how we think about Death

Mockito Build-operate-check pattern

Page 8: How ANDROID TESTING changed how we think about Death

Mock initizalition

Page 9: How ANDROID TESTING changed how we think about Death

Initizalition using mockito test runner

Page 10: How ANDROID TESTING changed how we think about Death

Let’s verify some behaviour

Page 11: How ANDROID TESTING changed how we think about Death

Argument matchers

Page 12: How ANDROID TESTING changed how we think about Death

Verifying number of invocations / at least x / never

Page 13: How ANDROID TESTING changed how we think about Death

Making sure interaction(s) never happened on mock

Page 14: How ANDROID TESTING changed how we think about Death

Spying on real objects

Page 15: How ANDROID TESTING changed how we think about Death

Sounds familiar???

Page 16: How ANDROID TESTING changed how we think about Death

Allows you to run your android code on JVM.

Allows loading of Android Classes in pure Java Projects.

TO THE RESCUE…

Page 17: How ANDROID TESTING changed how we think about Death

Shadow Objects!

Page 18: How ANDROID TESTING changed how we think about Death

View and Resource Loading…

Page 19: How ANDROID TESTING changed how we think about Death

Shadow Activity

Shadow ImageView

Page 20: How ANDROID TESTING changed how we think about Death

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

Robolectric 2.0+

Page 21: How ANDROID TESTING changed how we think about Death

Perform click Sample

Page 22: How ANDROID TESTING changed how we think about Death

Started Activity test

Should have fragment test

Page 23: How ANDROID TESTING changed how we think about Death

Device Configuration Sample

Page 24: How ANDROID TESTING changed how we think about Death

Network sample

Robolectric acts as a proxy!!!

Page 25: How ANDROID TESTING changed how we think about Death

Creating your own shadows

Page 26: How ANDROID TESTING changed how we think about Death

Creating your own shadows

Page 27: How ANDROID TESTING changed how we think about Death

Creating your own shadows

Page 28: How ANDROID TESTING changed how we think about Death

•  A library by square (FTW!) •  It gives a chainable (or “fluent”)

syntax for checking assertions. •  Makes tests easier to write (and

read!).

FEST Android

Page 29: How ANDROID TESTING changed how we think about Death

Sample: code to modify a bitmap

Page 30: How ANDROID TESTING changed how we think about Death

Assertions with FEST

Page 31: How ANDROID TESTING changed how we think about Death

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?

Page 32: How ANDROID TESTING changed how we think about Death

Dagger

Directed Acyclic Graph

Page 33: How ANDROID TESTING changed how we think about Death

Dagger Graph sample

Page 34: How ANDROID TESTING changed how we think about Death

Dagger sample

Page 35: How ANDROID TESTING changed how we think about Death

Declare dependencies

Page 36: How ANDROID TESTING changed how we think about Death

Satisfy dependencies

Page 37: How ANDROID TESTING changed how we think about Death

Build the graph

Page 38: How ANDROID TESTING changed how we think about Death

Modules

Page 39: How ANDROID TESTING changed how we think about Death

Spoon •  Acceptance tests (black box) •  Automation of test execution across multiple

devices •  Aggregation of the results

Page 40: How ANDROID TESTING changed how we think about Death

Spoon •  Aggregation of screenshots while your tests

are running

Page 41: How ANDROID TESTING changed how we think about Death

•  Robojuice •  Robotium •  Android Testing Framework •  UI Automator •  Monkey Runner

More tools…

Page 42: How ANDROID TESTING changed how we think about Death

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…

Page 43: How ANDROID TESTING changed how we think about Death
Page 44: How ANDROID TESTING changed how we think about Death

Questions?

Page 45: How ANDROID TESTING changed how we think about Death

@fernando_cejas https://github.com/android10

[email protected] http://corporate.tuenti.com/es/dev/blog

THANKS!!!