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.

World-Class Testing Development Pipeline for Android

8,377 views

Published on

World-Class Testing Development Pipeline for Android

Published in: Engineering
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

World-Class Testing Development Pipeline for Android

  1. 1. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs World-Class Testing Development Pipeline for Android Pedro Vicente Gómez Sánchez Senior Mobile Developer at Karumi pedro@karumi.com @pedro_g_s github.com/pedrovgs
  2. 2. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
  3. 3. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Alberto Gragera Technical Director Jorge Barroso Google Developer Expert Davide Mendolia Senior Full Stack Engineer Sergio Gutierrez Senior Mobile Engineer
  4. 4. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Let’s talk about testing!
  5. 5. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs This talk starts with some common problems.
  6. 6. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs What do we have to test and how?
  7. 7. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs What if our code is not testable?
  8. 8. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Just because our tests are passing doesn’t mean your code is working.
  9. 9. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Any conclusions?
  10. 10. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs We are doing something wrong if we can’t trust our tests. We need a solution.
  11. 11. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The Solution: Testable Code + Testing Pipeline
  12. 12. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The Software Architecture used has to hide implementation details.
  13. 13. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Dependency Inversion Principle is going to guide your Architecture. DIP is the most important S.O.L.I.D. principle.
  14. 14. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Architecture - Testable Code Activity View Presenter Use Case Repository Repository Domain Model Data Source Data Source Data Source Implementation Data Source Implementation Use Case Use Case
  15. 15. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Architecture is not enough.
  16. 16. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Testing Development Pipeline
  17. 17. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Your Testing Development Pipeline should define what you are going to test and how.
  18. 18. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs What do I want to test?
  19. 19. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test my code implements the business requirements.
  20. 20. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test my API Client, HTTP requests/responses and JSON parsing, are working as expected.
  21. 21. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test the user is watching in the App UI the expected messages.
  22. 22. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs In other words…
  23. 23. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test our Business Logic independently of frameworks or libraries. Test our integration with the API. Test our application UI.
  24. 24. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs These three points define part of the Testing Development Pipeline. These three points define what we want to test.
  25. 25. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs How are we going to test this?
  26. 26. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test my code implements the business requirements.
  27. 27. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Think in the test scope and try to check the state of the software at the end of the test execution. Use the Dependency Inversion Principle to be able to use test doubles to simulate different test scenarios and adjust the test scope. Business Logic Tests
  28. 28. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Show me the code!
  29. 29. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Check the state of the software at the end of the test execution
  30. 30. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Implementation Details are replaced using Test Doubles. The SUT is the GameBoy, the GBZ80 and the GPU.
  31. 31. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Infrastructure needed?
  32. 32. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The usage of test doubles are the key to adjust the test scope. The Application architecture will help use to hide implementation details applying the dependency inversion principle
  33. 33. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Now we can test our business logic without depending on any framework or library. Inside an isolated environment. The Result
  34. 34. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test my API Client, HTTP requests/responses and JSON parsing, are working as expected.
  35. 35. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Start a fake server we have under control checking the API client is working given some preconfigured scenarios. API Client tests
  36. 36. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Show me the code!
  37. 37. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Given some HTTP responses the final authentication state is correct.
  38. 38. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Given a Json file with the response, an http status code, and an endpoint the parsing is correct.
  39. 39. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Infrastructure needed?
  40. 40. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Initializes a fake http server where we can configure responses.
  41. 41. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Now we can check if our integration with the API Client is working as it should. The Result
  42. 42. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Test the user is watching in the App UI the expected messages.
  43. 43. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs UI Tests Replace some dependencies using test doubles from the testing application to be able to simulate different scenarios and check the UI is showing the correct information.
  44. 44. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Show me the code!
  45. 45. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Code Injected from the test application.
  46. 46. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Asserts from the UI point of view.
  47. 47. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Asserts from the User Interface point of view.
  48. 48. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Helper methods or different creational patterns to create initial scenarios.
  49. 49. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Infrastructure needed?
  50. 50. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Configure your dependency injection library from your Application class.
  51. 51. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Mocking Library Helper Methods
  52. 52. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Replace Application’s dependency container with a custom configuration.
  53. 53. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Now we can write UI tests easily. The Result
  54. 54. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The Testing Development Pipeline is complete now. Now we know what to test and how.
  55. 55. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Now we can trust our tests.
  56. 56. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Tools and libraries?
  57. 57. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Business Logic Tests ● JUnit. ● Mockito.
  58. 58. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs API Client Tests ● JUnit. ● Mockito. ● MockWebServer.
  59. 59. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs UI Tests ● JUnit. ● Mockito. ● Robolectric. ● Espresso. ● Dagger.
  60. 60. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs References ● World-Class Testing Development Pipeline for Android blog post series. ● Kata Contacts. GitHub Repository. ● Kata TODO API Client. GitHub Repository. ● Kata Super Heroes. GitHub Repository. ● Android GameBoy Emulator. GitHub Repository. ● Google Testing Blog. Testing state vs interaction.
  61. 61. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Questions?

×