Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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	...
Test first ?
•  Generally easier
•  Eliminates external dependencies
•  Easily repeatable
The Acceptance Tests cycle
	
  	
  
	
  	
  
Write	
  
UI	
  test	
  
Implement	
  
Refactor	
  
Write	
  unit	
  
test	
 ...
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 c...
gwen
	
  given(user).isNear(lexington());	
  
	
  given(server).returns(lustForLife());	
  
	
  	
  
	
  when(user).shazam...
Other libraries for Acceptance Tests
•  Espresso
•  Robotium
•  Fork
•  HamMock Server
The Unit tests cycle
	
  	
  
	
  	
  
Write	
  UI	
  
test	
  
Implement	
  
Refactor	
  
Write	
  
unit	
  test	
  
BDD	...
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	
  ca...
Activity
	
  public	
  class	
  ResultActivity	
  extends	
  Activity	
  implements	
  ResultView	
  {	
  
	
  	
  	
  pri...
Presenter
public	
  class	
  ResultPresenter	
  {	
  
	
  
	
  public	
  ResultPresenter(ResultView	
  resultView,	
  Venu...
View
	
  public	
  interface	
  ResultView	
  {	
  
	
  
	
  	
  	
  	
  void	
  showResult(Result	
  track);	
  
	
  
	
 ...
Activity as View
	
  public	
  class	
  ResultActivity	
  extends	
  Activity	
  implements	
  ResultView	
  {	
  
	
  
	
...
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
Upcoming SlideShare
Loading in …5
×

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

7,889 views

Published on

Shazam is a very popular audio recognition app. It is installed on 100M+ Android devices and it’s growing rapidly. In this talk, we will address how we made the release schedule faster, more predictable and with more features by using BDD and automation testing.

I'd like to demonstrate how that can be done without slowing down or hindering the development process and why our developers actually find writing tests is fun. Finally, we’ll look at how our testing strategy has translated to our testing framework and hardware infrastructure.

  • Follow the link, new dating source: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

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

  1. 1. How to build rock-solid apps & keep 100m+ users happy Iordanis Giannakakis @iordanis_g#devoxx #dv14
  2. 2. How does Shazam work?
  3. 3. Some numbers
  4. 4. Happy users Even developers?
  5. 5. Automated testing
  6. 6. Faster releases
  7. 7. Better code
  8. 8. Cheaper http://testdroid.com/testdroid/5851
  9. 9. Easy
  10. 10. A user walks into a bar
  11. 11. Doing it the test driven way         Write   UI  test   Implement   Refactor   Write  unit   test   BDD   TDD  
  12. 12. Test first ? •  Generally easier •  Eliminates external dependencies •  Easily repeatable
  13. 13. The Acceptance Tests cycle         Write   UI  test   Implement   Refactor   Write  unit   test   BDD   TDD  
  14. 14. Acceptance criteria •  Given: arrange •  When: act •  Then: assert
  15. 15. 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
  16. 16. gwen  given(user).isNear(lexington());    given(server).returns(lustForLife());        when(user).shazams();      then(user).canCheckIn(lustForLife(),  lexington());   http://github.com/shazam/gwen
  17. 17. Other libraries for Acceptance Tests •  Espresso •  Robotium •  Fork •  HamMock Server
  18. 18. The Unit tests cycle         Write  UI   test   Implement   Refactor   Write   unit  test   BDD   TDD  
  19. 19. What we don’t test Activities & Fragments http://github.com/xxv/android-lifecycle
  20. 20. What we don’t test
  21. 21. What we do test •  Presentation logic •  Business logic
  22. 22. The MVP pattern Presenter Model View
  23. 23. The MVP pattern Presenter Model View Android
  24. 24. The MVP pattern •  Makes presentation logic testable •  Avoid Android dependencies •  No need to test “dummy” view
  25. 25. Dependency Injection •  Breaks hardcoded dependencies •  Alternatives for runtime & tests •  Behaviour vs implementation
  26. 26. Feature X Hardcoded dependencies Client Feature X
  27. 27. Dependency Injection Client Feature X Interface Injector  
  28. 28. 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?          }    }  
  29. 29. 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();        }    }  
  30. 30. 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);            }        });    }   }  
  31. 31. View  public  interface  ResultView  {            void  showResult(Result  track);            void  showCheckInPrompt(Venue  venue);    }  
  32. 32. 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          }    }  
  33. 33. Other Unit Test technologies •  JUnit 4 •  Robolectric java.lang.RuntimeException: Stub! •  Hamcrest •  JMock
  34. 34. Test execution
  35. 35. Continuous Integration
  36. 36. Speed (Hint: slow)
  37. 37. Usual execution Test  Suite  
  38. 38. Spoon http://github.com/square/spoon
  39. 39. Fork http://github.com/shazam/fork Test  Suite  
  40. 40. Demo http://github.com/shazam/fork
  41. 41. Fork http://github.com/shazam/fork
  42. 42. Fork http://github.com/shazam/fork •  Pooled execution •  Infinitely scalable •  Current setup 1 test / 2 seconds
  43. 43. Flakiness monitor
  44. 44. ADB Remote http://github.com/sleekweasel/CgiAdbRemote
  45. 45. If all else fails
  46. 46. If all else fails
  47. 47. If all else fails
  48. 48. Summary •  Testing is easier than you may think •  Practice, practice, practice •  Toolset is limited but getting better
  49. 49. Questions? @iordanis_g +IordanisGiannakakis

×