$30 off During Our Annual Pro Sale. View Details »

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. TESTING IT & LOVING IT ZAN MARKAN

  2. THE WHAT AGENDA ▸ Motivation ▸ Testing 101 ▸ How

    do I… ▸ ♥ It
  3. MOTIVATION - 2 REASONS REASON[0]

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

    - a company at scale “MOVE FAST AND KNOW WHEN THINGS BREAK” - me
  5. MOTIVATION - 2 REASONS java.lang.ArrayIndexOutOfBoundsException: 2

  6. TESTING 101 WHAT IS THIS “TESTING” THING?

  7. 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
  8. TESTING 101 ANATOMY OF A TEST ▸ System under test

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

    Time ▸ FREE architecture (to some extent) ▸ For love of money…
  10. 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? ▸
  11. 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
  12. HOW DO I…? TALES FROM THE TRENCHES

  13. 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
  14. HOW DO I… UNIT TESTING BEST PRACTICES ▸ BFFs: POJOs,

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

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

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

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

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

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

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

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

    Easy to test functions individually ▸ Mocking functions ▸ Observable.toBlocking() ▸ TestScheduler
  24. …AND LOVING IT OTHER FUN STUFF

  25. 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
  26. LOVING IT A NICE TIME TO TRY KOTLIN Source: Antonio

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

    @zmarkan ▸ Reddit /r/androiddev /u/zmarkan ▸ www.spacecowboyrocketcompany.com ▸ zan@markan.me
  28. 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