Top Banner
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 Second Edition android10.org
47

How ANDROID TESTING changed how we think about Death - Second Edition

Aug 18, 2015

Download

Engineering

Fernando Cejas
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How ANDROID TESTING changed how we think about Death - Second Edition

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

Second Edition

android10.org

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

Who am I… •  Software Engineer •  GDG Barcelona Organizer

android10.org

•  Android lover •  Geek •  Gintonic fan…

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

Agenda?

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

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 - Second Edition

•  Unit testing •  Integration Testing •  Functional and System Testing

1.  Stress Testing 2.  Performance Testing 3.  Usability Testing

•  Acceptance Testing •  Regression Testing

1.  Smoke Testing

Types of tests…

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

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

expectation"

What is this mock thing?

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

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 8: How ANDROID TESTING changed how we think about Death - Second Edition

Mockito Build-operate-check pattern

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

Mock initizalition

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

Initizalition using mockito test runner

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

Let’s verify some behaviour

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

Argument matchers

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

Verifying number of invocations / at least x / never

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

Making sure interaction(s) never happened on mock

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

Spying on real objects

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

Sounds familiar???

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

Allows you to run your android code on JVM.

Allows loading of Android Classes in pure Java Projects.

TO THE RESCUE…

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

Shadow Objects!

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

View and Resource Loading…

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

Shadow Activity

Shadow ImageView

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

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

Robolectric 2.0+

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

Perform click Sample

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

Started Activity test

Should have fragment test

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

Device Configuration Sample

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

Network sample

Robolectric acts as a proxy!!!

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

Creating your own shadows

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

Creating your own shadows

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

Creating your own shadows

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

•  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 30: How ANDROID TESTING changed how we think about Death - Second Edition

Sample: code to modify a bitmap

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

Assertions with FEST

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

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 33: How ANDROID TESTING changed how we think about Death - Second Edition

Dagger

Directed Acyclic Graph

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

Dagger Graph sample

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

Dagger sample

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

Declare dependencies

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

Satisfy dependencies

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

Build the graph

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

Modules

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

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

devices •  Aggregation of the results

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

Spoon •  Aggregation of screenshots while your tests

are running

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

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

More tools…

Page 43: How ANDROID TESTING changed how we think about Death - Second Edition

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 44: How ANDROID TESTING changed how we think about Death - Second Edition

DO NOT LET YOUR CODE TO BE BROKEN…

DO NOT BREAK EXISTING FUNCTIONLITY…

Page 45: How ANDROID TESTING changed how we think about Death - Second Edition
Page 46: How ANDROID TESTING changed how we think about Death - Second Edition

Questions?

Page 47: How ANDROID TESTING changed how we think about Death - Second Edition

@fernando_cejas https://github.com/android10

http://android10.org

THANKS!!!