Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing it & Loving it

Zan Markan
November 13, 2015

Testing it & Loving it

Talk about Android testing, given at Big Android BBQ Amsterdam 2015.

It is about testing approaches you can take to make your Android apps better, more resilient and have some good experience in the process.

Zan Markan

November 13, 2015
Tweet

More Decks by Zan Markan

Other Decks in Programming

Transcript

  1. MOTIVATION - 2 REASONS REASON[1] “MOVE FAST AND BREAK THINGS”

    - a company at scale “MOVE FAST AND KNOW WHEN THINGS BREAK” - me
  2. 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
  3. TESTING 101 ANATOMY OF A TEST ▸ System under test

    ▸ Preconditions ▸ Input ▸ Expected output
  4. TESTING 101 WHY TEST? ▸ FREE documentation ▸ More FREE

    Time ▸ FREE architecture (to some extent) ▸ For love of money…
  5. 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? ▸
  6. 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
  7. 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
  8. HOW DO I… UNIT TESTING BEST PRACTICES ▸ BFFs: POJOs,

    Mocks and Interfaces ▸ No statics and com.android.* allowed ▸ Wrap it!
  9. HOW DO I… TEST DRIVEN WHAT?? ▸ Not just for

    purists ▸ Red - Green - Refactor ▸ Drives design ▸ Free code coverage ▸ Learn by doing Katas
  10. HOW DO I… …IN THE LAND OF MVP ▸ Model

    - View - Presenter pattern ▸ The most popular Android architecture at present ▸ (after spaghetti code) ▸ Easily testable
  11. HOW DO I… MVP - MODEL ▸ Pure Java ▸

    Unit tests - jUnit, Mockito ▸ Business logic ▸ Easiest to test
  12. HOW DO I… MVP - PRESENTER ▸ Still pure Java

    (ideally) ▸ (Fairly) clean architecture ▸ Lots of interfaces, piping…
  13. HOW DO I… MVP - VIEW ▸ Tied with framework

    :( ▸ No pure java testing, apart from Robolectric ▸ Espresso, Android Instrumentation, Calabash… ▸ Integration testing?
  14. HOW DO I… ROBOLECTRIC ▸ TDD on the views ▸

    Katas - http://coreylatislaw.com/robolectric-kata/ ▸ Shadow classes != Android framework ▸ So simple, it’s dangerous
  15. 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?
  16. HOW DO I… MORE TESTING SHENANIGANS ▸ Functional/End 2 End

    ▸ BDD-ish ▸ Calabash, Robotium, Appium and other -iums. ▸ Device clouds ▸ Can take forever
  17. HOW DO I… RXJAVA (WE’VE ALL HEARD ABOUT THAT) ▸

    Easy to test functions individually ▸ Mocking functions ▸ Observable.toBlocking() ▸ TestScheduler
  18. 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
  19. LOVING IT A NICE TIME TO TRY KOTLIN Source: Antonio

    Leiva - Kotlin for Android Developers http://antonioleiva.com/kotlin-android-developers-book/
  20. FIN GET IN TOUCH ▸ Twitter: @zmarkan ▸ Slack https://androidchat.co/

    @zmarkan ▸ Reddit /r/androiddev /u/zmarkan ▸ www.spacecowboyrocketcompany.com ▸ [email protected]
  21. 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