SlideShare a Scribd company logo
1 of 49
Download to read offline
How to build
rock-solid apps
& keep 100m+ users happy
Iordanis Giannakakis
@iordanis_g#devoxx #dv14
How does Shazam work?
Some numbers
Happy users
Even developers?
Automated testing
Faster releases
Better code
Cheaper
http://testdroid.com/testdroid/5851
Easy
A user walks into a bar
Doing it the test driven way
	
  	
  
	
  	
  
Write	
  
UI	
  test	
  
Implement	
  
Refactor	
  
Write	
  unit	
  
test	
  
BDD	
  
TDD	
  
Test first ?
•  Generally easier
•  Eliminates external dependencies
•  Easily repeatable
The Acceptance Tests cycle
	
  	
  
	
  	
  
Write	
  
UI	
  test	
  
Implement	
  
Refactor	
  
Write	
  unit	
  
test	
  
BDD	
  
TDD	
  
Acceptance criteria
•  Given: arrange
•  When: act
•  Then: assert
Example
Given a user is near a music venue
And the server returns a known result
When the user Shazams
Then the user can check-in their discovery
gwen
	
  given(user).isNear(lexington());	
  
	
  given(server).returns(lustForLife());	
  
	
  	
  
	
  when(user).shazams();	
  
	
  
	
  then(user).canCheckIn(lustForLife(),	
  lexington());	
  
http://github.com/shazam/gwen
Other libraries for Acceptance Tests
•  Espresso
•  Robotium
•  Fork
•  HamMock Server
The Unit tests cycle
	
  	
  
	
  	
  
Write	
  UI	
  
test	
  
Implement	
  
Refactor	
  
Write	
  
unit	
  test	
  
BDD	
  
TDD	
  
What we don’t test
Activities & Fragments
http://github.com/xxv/android-lifecycle
What we don’t test
What we do test
•  Presentation logic
•  Business logic
The MVP pattern
Presenter
Model View
The MVP pattern
Presenter
Model View
Android
The MVP pattern
•  Makes presentation logic testable
•  Avoid Android dependencies
•  No need to test “dummy” view
Dependency Injection
•  Breaks hardcoded dependencies
•  Alternatives for runtime & tests
•  Behaviour vs implementation
Feature X
Hardcoded dependencies
Client
Feature X
Dependency Injection
Client
Feature X
Interface
Injector	
  
Model
	
  public	
  interface	
  VenueRetriever	
  {	
  
	
  	
  	
  	
  void	
  findClosestVenue(VenueFoundCallback	
  callback);	
  
	
  }	
  
	
  
	
  public	
  class	
  NetworkVenueRetriever	
  implements	
  VenueRetriever	
  {	
  
	
  	
  	
  	
  public	
  void	
  findClosestVenue(VenueFoundCallback	
  callback)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  //	
  Some	
  slow	
  networking	
  
	
  	
  	
  	
  }	
  
	
  }	
  
	
  
	
  public	
  class	
  LocalVenueRetriever	
  implements	
  VenueRetriever	
  {	
  
	
  	
  	
  	
  public	
  void	
  findClosestVenue(VenueFoundCallback	
  callback)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  //	
  DB	
  look-­‐up	
  /	
  caching	
  layer,	
  perhaps?	
  
	
  	
  	
  	
  }	
  
	
  }	
  
Activity
	
  public	
  class	
  ResultActivity	
  extends	
  Activity	
  implements	
  ResultView	
  {	
  
	
  	
  	
  private	
  final	
  VenueRetriever	
  venueRetriever	
  =	
  venueRetriever();	
  
	
  	
  	
  private	
  ResultPresenter	
  resultPresenter;	
  
	
  
	
  	
  	
  public	
  void	
  onCreate(Bundle	
  savedInstanceState)	
  {	
  
	
  	
  	
  	
  	
  //	
  TODO:	
  Setup	
  layouts	
  &	
  views	
  	
  
	
  	
  	
  	
  	
  Result	
  result	
  =	
  resultToDisplay();	
  
	
  	
  	
  	
  	
  resultPresenter	
  =	
  new	
  ResultPresenter(this,	
  venueRetriever,	
  result);	
  
	
  	
  	
  }	
  
	
  
	
  	
  	
  public	
  void	
  onStart()	
  {	
  
	
  	
  	
  	
  	
  resultPresenter.startPresenting();	
  
	
  	
  	
  }	
  
	
  }	
  
Presenter
public	
  class	
  ResultPresenter	
  {	
  
	
  
	
  public	
  ResultPresenter(ResultView	
  resultView,	
  VenueRetriever	
  venueRetriever,	
  Result	
  res){	
  
	
  	
  	
  this.resultView	
  =	
  resultView;	
  
	
  	
  	
  this.venueRetriever	
  =	
  venueRetriever;	
  
	
  	
  	
  this.result	
  =	
  res;	
  
	
  }	
  
	
  
	
  public	
  void	
  startPresenting()	
  {	
  
	
  	
  	
  resultView.showResult(result);	
  
	
  	
  	
  venueRetriever.findClosestVenue(new	
  VenueFoundCallback()	
  {	
  
	
  	
  	
  	
  	
  public	
  void	
  venueFound(Venue	
  venue)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  resultView.showCheckInPrompt(venue);	
  
	
  	
  	
  	
  	
  }	
  
	
  	
  	
  });	
  
	
  }	
  
}	
  
View
	
  public	
  interface	
  ResultView	
  {	
  
	
  
	
  	
  	
  	
  void	
  showResult(Result	
  track);	
  
	
  
	
  	
  	
  	
  void	
  showCheckInPrompt(Venue	
  venue);	
  
	
  }	
  
Activity as View
	
  public	
  class	
  ResultActivity	
  extends	
  Activity	
  implements	
  ResultView	
  {	
  
	
  
	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  public	
  void	
  showResult(Result	
  result)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  //TODO	
  show	
  the	
  result	
  screen	
  &	
  bind	
  result	
  data	
  
	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  public	
  void	
  showCheckInPrompt(Venue	
  venue)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  //TODO	
  bind	
  the	
  venue	
  with	
  check-­‐in	
  prompt	
  view	
  
	
  	
  	
  	
  }	
  
	
  }	
  
Other Unit Test technologies
•  JUnit 4
•  Robolectric
java.lang.RuntimeException: Stub!
•  Hamcrest
•  JMock
Test execution
Continuous Integration
Speed (Hint: slow)
Usual execution
Test	
  Suite	
  
Spoon
http://github.com/square/spoon
Fork
http://github.com/shazam/fork
Test	
  Suite	
  
Demo
http://github.com/shazam/fork
Fork
http://github.com/shazam/fork
Fork
http://github.com/shazam/fork
•  Pooled execution
•  Infinitely scalable
•  Current setup 1 test / 2 seconds
Flakiness monitor
ADB Remote
http://github.com/sleekweasel/CgiAdbRemote
If all else fails
If all else fails
If all else fails
Summary
•  Testing is easier than you may think
•  Practice, practice, practice
•  Toolset is limited but getting better
Questions?
@iordanis_g
+IordanisGiannakakis

More Related Content

What's hot

Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationRichard North
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersNaresha K
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptNir Elbaz
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14Peter Foerger
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c Hermione
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c HermioneJS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c Hermione
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c HermioneJSFestUA
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Stacy Devino
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Christian Johansen
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design PatternsGodfrey Nolan
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
The Gradle in Ratpack: Dissected
The Gradle in Ratpack: DissectedThe Gradle in Ratpack: Dissected
The Gradle in Ratpack: DissectedDavid Carr
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Fwdays
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzlesDanny Preussler
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Libraryasync_io
 

What's hot (20)

Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScript
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14DalekJS Workshop at T3DD14
DalekJS Workshop at T3DD14
 
Javascript Unit Testing
Javascript Unit TestingJavascript Unit Testing
Javascript Unit Testing
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c Hermione
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c HermioneJS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c Hermione
JS Fest 2018. Сергей Пузанков. E2E-тестирование фронтенда c Hermione
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
The Gradle in Ratpack: Dissected
The Gradle in Ratpack: DissectedThe Gradle in Ratpack: Dissected
The Gradle in Ratpack: Dissected
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzles
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 

Similar to How to build rock solid apps & keep 100m+ users happy

How to build rock solid apps and keep 100m+ users happy
How to build rock solid apps and keep 100m+ users happyHow to build rock solid apps and keep 100m+ users happy
How to build rock solid apps and keep 100m+ users happyIordanis (Jordan) Giannakakis
 
Keeping 100m+ users happy: How we test Shazam on Android
Keeping 100m+ users happy: How we test Shazam on AndroidKeeping 100m+ users happy: How we test Shazam on Android
Keeping 100m+ users happy: How we test Shazam on AndroidIordanis (Jordan) Giannakakis
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developersAnton Udovychenko
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]Nilhcem
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EEAlexis Hassler
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and FriendsYun Zhi Lin
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
End to-end testing from rookie to pro
End to-end testing  from rookie to proEnd to-end testing  from rookie to pro
End to-end testing from rookie to proDomenico Gemoli
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineJavier de Pedro López
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Altitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly WorkshopAltitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly WorkshopFastly
 
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)Tobias Schneck
 
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...Tobias Schneck
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 

Similar to How to build rock solid apps & keep 100m+ users happy (20)

How to build rock solid apps and keep 100m+ users happy
How to build rock solid apps and keep 100m+ users happyHow to build rock solid apps and keep 100m+ users happy
How to build rock solid apps and keep 100m+ users happy
 
Keeping 100m+ users happy: How we test Shazam on Android
Keeping 100m+ users happy: How we test Shazam on AndroidKeeping 100m+ users happy: How we test Shazam on Android
Keeping 100m+ users happy: How we test Shazam on Android
 
Rcp by example
Rcp by exampleRcp by example
Rcp by example
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developers
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
End to-end testing from rookie to pro
End to-end testing  from rookie to proEnd to-end testing  from rookie to pro
End to-end testing from rookie to pro
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Altitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly WorkshopAltitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly Workshop
 
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)
UI Testing - Selenium? Rich-Clients? Containers? (SwanseaCon 2018)
 
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...
Containerized End-2-End Testing - Agile Testing Meetup at Süddeutsche Zeitung...
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 

How to build rock solid apps & keep 100m+ users happy