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]