Upgrade to Pro — share decks privately, control downloads, hide ads and more …

World-Class Testing Development Pipeline for An...

Karumi
June 11, 2016

World-Class Testing Development Pipeline for Android & iOS

World-Class Testing Development Pipeline for Android & iOS.

Description:

Test our applications is not an easy task. When we start writing tests most of the time we don’t know what to test and how, our code is not as testable as it should, we write tests but sometimes they are flaky or test nothing. In this talk we are going to talk about what to test an how to design a testing development pipeline. Using real production code we will show how to test our application using different approaches based on different testing strategies and frameworks or libraries like: Espresso, Kif, MockWebServer, Nocilla, Dagger2, JUnit, XCTest, Mockito, etc.

If you want to learn how to design a testing development pipeline, how to test your application layers using different strategies and write tests you can trust, this is your talk.

Karumi

June 11, 2016
Tweet

More Decks by Karumi

Other Decks in Technology

Transcript

  1. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    World-Class Testing Development Pipeline for Mobile Pedro Vicente Gómez Sánchez Senior Mobile Developer at Karumi [email protected] @pedro_g_s github.com/pedrovgs
  2. Pedro V. Gómez Sánchez - [email protected] - @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
  3. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Just because your tests are passing doesn’t mean your code is working.
  4. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    We are doing something wrong if we can’t trust our tests. We need a solution to this problem.
  5. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    The Software Architecture used has to hide implementation details.
  6. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Dependency Inversion Principle is going to guide your Architecture. Talking about testing, the DIP is the most important S.O.L.I.D. principle.
  7. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Architecture - Testable Code Activity - View Controller View Presenter Use Case Repository Repository Domain Model Data Source Data Source Data Source Implementation Data Source Implementation Use Case Use Case
  8. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Your Testing Development Pipeline should define what you are going to test and how.
  9. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Test my API Client, HTTP requests/responses and JSON parsing, are working as expected.
  10. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Test the user is watching in the App UI the expected messages.
  11. Pedro V. Gómez Sánchez - [email protected] - @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.
  12. Pedro V. Gómez Sánchez - [email protected] - @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.
  13. Pedro V. Gómez Sánchez - [email protected] - @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
  14. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Check the state of the software at the end of the test execution
  15. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Implementation Details are replaced using Test Doubles. The SUT is the GameBoy, the GBZ80 and the GPU.
  16. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    The usage of test doubles are the key to adjust the test scope. The Application architecture will help us to hide implementation details applying the dependency inversion principle.
  17. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Check the state of the software at the end of the test execution
  18. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Implementation Details are replaced using Test Doubles. But in the case of iOS is just for simplicity. The SUT is the GameBoy, the GBZ80 and the GPU.
  19. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Handmade test doubles :_( The Application architecture will help us to hide implementation details applying the dependency inversion principle.
  20. Pedro V. Gómez Sánchez - [email protected] - @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
  21. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Test my API Client, HTTP requests/responses and JSON parsing, are working as expected.
  22. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Start a fake server listening at some endpoints or use Objective-C swizzling, to test the API client is working given some preconfigured scenarios. API Client tests
  23. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Given some HTTP responses the final authentication state is correct.
  24. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Given a Json file with the response, an http status code, and an endpoint the parsing is correct.
  25. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Initializes a fake http server where we can configure responses.
  26. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Given some HTTP responses the final authentication state is correct.
  27. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Given a Json file with the response, an http status code, and an endpoint the parsing is correct.
  28. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Now we can check if our integration with the API Client is working as it should. The Result
  29. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Test the user is watching in the App UI the expected messages.
  30. Pedro V. Gómez Sánchez - [email protected] - @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.
  31. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Configure your dependency injection library from your Application class.
  32. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Replace Application’s dependency container with a custom configuration.
  33. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Now we can write UI tests without a real server. The Result
  34. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    The Testing Development Pipeline is complete now. Now we know what to test and how.
  35. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    Business Logic Tests • JUnit. • Mockito. • XCTest. • Your hands.
  36. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    API Client Tests • JUnit. • Mockito. • MockWebServer. • XCTest. • Your hands. • Nocilla.
  37. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    UI Tests • JUnit. • Mockito. • Robolectric. • Espresso. • Dagger. • XCTest. • Your hands. • KIF • Creational patterns.
  38. Pedro V. Gómez Sánchez - [email protected] - @pedro_g_s - github.com/pedrovgs

    References • World-Class Testing Development Pipeline for Android blog post series. • Kata Contacts. GitHub Repository Android. - GitHub Repository iOS • Kata TODO API Client. GitHub Repository Android - GitHub Repository iOS. • Kata Super Heroes. GitHub Repository Android - GitHub Repository iOS • Android GameBoy Emulator. GitHub Repository. • Google Testing Blog. Testing state vs interaction.