Slide 1

Slide 1 text

TESTING IT & LOVING IT ZAN MARKAN

Slide 2

Slide 2 text

THE WHAT AGENDA ▸ Motivation ▸ Testing 101 ▸ How do I… ▸ ♥ It

Slide 3

Slide 3 text

MOTIVATION - 2 REASONS REASON[0]

Slide 4

Slide 4 text

MOTIVATION - 2 REASONS REASON[1] “MOVE FAST AND BREAK THINGS” - a company at scale “MOVE FAST AND KNOW WHEN THINGS BREAK” - me

Slide 5

Slide 5 text

MOTIVATION - 2 REASONS java.lang.ArrayIndexOutOfBoundsException: 2

Slide 6

Slide 6 text

TESTING 101 WHAT IS THIS “TESTING” THING?

Slide 7

Slide 7 text

TESTING 101 WHAT IS THIS “TESTING” THING ▸ You are doing it already ▸ Just get the computer to do it, and call it “automated”! ▸ Hint, it’s not just for QA ▸ …and it takes many shapes & forms

Slide 8

Slide 8 text

TESTING 101 ANATOMY OF A TEST ▸ System under test ▸ Preconditions ▸ Input ▸ Expected output

Slide 9

Slide 9 text

TESTING 101 WHY TEST? ▸ FREE documentation ▸ More FREE Time ▸ FREE architecture (to some extent) ▸ For love of money…

Slide 10

Slide 10 text

TESTING 101 WHAT TO TEST ▸ Frontend vs Backend code ▸ Config changes ▸ What happens when you time travel… ▸ Remember when the API developer tried to murder you? ▸

Slide 11

Slide 11 text

TESTING 101 THE MANDATORY PYRAMID OF TESTS Source: Google Testing blog http://googletesting.blogspot.nl/2015/04/just-say-no-to-more-end-to-end-tests.html

Slide 12

Slide 12 text

HOW DO I…? TALES FROM THE TRENCHES

Slide 13

Slide 13 text

HOW DO I… UNIT TESTING ▸ Fast and simple ▸ Test the public “API” on a class level ▸ If it’s hard, you’re doing it wrong ▸ Having fun with mocks ▸ Great for TDD

Slide 14

Slide 14 text

HOW DO I… UNIT TESTING BEST PRACTICES ▸ BFFs: POJOs, Mocks and Interfaces ▸ No statics and com.android.* allowed ▸ Wrap it!

Slide 15

Slide 15 text

HOW DO I… TEST DRIVEN WHAT?? ▸ Not just for purists ▸ Red - Green - Refactor ▸ Drives design ▸ Free code coverage ▸ Learn by doing Katas

Slide 16

Slide 16 text

HOW DO I… …IN THE LAND OF MVP ▸ Model - View - Presenter pattern ▸ The most popular Android architecture at present ▸ (after spaghetti code) ▸ Easily testable

Slide 17

Slide 17 text

HOW DO I… MVP - MODEL ▸ Pure Java ▸ Unit tests - jUnit, Mockito ▸ Business logic ▸ Easiest to test

Slide 18

Slide 18 text

HOW DO I… MVP - PRESENTER ▸ Still pure Java (ideally) ▸ (Fairly) clean architecture ▸ Lots of interfaces, piping…

Slide 19

Slide 19 text

HOW DO I… MVP - VIEW ▸ Tied with framework :( ▸ No pure java testing, apart from Robolectric ▸ Espresso, Android Instrumentation, Calabash… ▸ Integration testing?

Slide 20

Slide 20 text

HOW DO I… ROBOLECTRIC ▸ TDD on the views ▸ Katas - http://coreylatislaw.com/robolectric-kata/ ▸ Shadow classes != Android framework ▸ So simple, it’s dangerous

Slide 21

Slide 21 text

HOW DO I… INSTRUMENTATION FRAMEWORK ▸ Runs on “proper” Android ▸ Espresso for fluent testing experience ▸ Test individual screens / activities /services/ applications ▸ Test flow between them ▸ Config changes much?

Slide 22

Slide 22 text

HOW DO I… MORE TESTING SHENANIGANS ▸ Functional/End 2 End ▸ BDD-ish ▸ Calabash, Robotium, Appium and other -iums. ▸ Device clouds ▸ Can take forever

Slide 23

Slide 23 text

HOW DO I… RXJAVA (WE’VE ALL HEARD ABOUT THAT) ▸ Easy to test functions individually ▸ Mocking functions ▸ Observable.toBlocking() ▸ TestScheduler

Slide 24

Slide 24 text

…AND LOVING IT OTHER FUN STUFF

Slide 25

Slide 25 text

LOVING IT TESTING PLAYGROUND ▸ They never see production, yet are still there ▸ New coding styles (drop hungarian notation, perhaps?) ▸ Architectural patterns ▸ Try new libraries with androidTestCompile and testCompile

Slide 26

Slide 26 text

LOVING IT A NICE TIME TO TRY KOTLIN Source: Antonio Leiva - Kotlin for Android Developers http://antonioleiva.com/kotlin-android-developers-book/

Slide 27

Slide 27 text

FIN GET IN TOUCH ▸ Twitter: @zmarkan ▸ Slack https://androidchat.co/ @zmarkan ▸ Reddit /r/androiddev /u/zmarkan ▸ www.spacecowboyrocketcompany.com ▸ [email protected]

Slide 28

Slide 28 text

DIRECTOR’S CUT (RE)SOURCES ▸ http://globalday.coderetreat.org/ ▸ https://google.github.io/android-testing-support-library/ ▸ http://calaba.sh/ ▸ https://aws.amazon.com/device-farm/ ▸ https://medium.com/ribot-labs/unit-testing-rxjava-6e9540d4a329 ▸ http://fedepaol.github.io/blog/2015/09/13/testing-rxjava-observables-subscriptions/ ▸ http://reactivex.io/RxJava/javadoc/ ▸ https://kotlinlang.org/docs/tutorials/koans.html