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

Network Testing

Network Testing

Introduction to Szimpla, a network testing library based on Snapshots that have been recorded before.

B0a336761194918a853deeff1f22b537?s=128

Pedro Piñera Buendía

July 08, 2016
Tweet

More Decks by Pedro Piñera Buendía

Other Decks in Programming

Transcript

  1. NETWORK TESTING @PEPIBUMUR - IOS DEVELOPER AT SOUNDCLOUD

  2. HOW MANY OF YOU IMPLEMENT UNIT TESTS IN YOUR PROJECTS?

    !
  3. SPECTA, EXPECTA, OCMOCK, OCMOCKITO, QUICK, NIMBLE, KIWI, OCHAMCREST

  4. WE TEST UNITS OF CODE !

  5. None
  6. ! CAN WORK AS EXPECTED ↔ BUT NOT THE INTEGRATION

  7. INTEGRATION TESTS

  8. WE TEST THE UNITS OF CODE AS A SYSTEM !

    ↔ !
  9. None
  10. BUT... YOUR COMPONENTS ARE USED BY VIEWCONTROLLERS

  11. AND THESE ONES HAVE A LIFECYCLE !

  12. CONTROLLED BY YOUR APPLICATION USERS !

  13. ! ARE PART OF THE SYSTEM

  14. ! ↔ # ↔ !

  15. AND WE SHOULD TEST IT... DON'T WE? !

  16. HOW MANY OF YOU IMPLEMENT ACCEPTANCE TESTS IN YOUR PROJECTS?

    !
  17. None
  18. THEY RELY ON ACCESSIBILITY THUS, THE UI LAYER

  19. let app = XCUIApplication() app.launch() app.buttons["Stream"].tap() app.tables.staticTexts["Enrique Iglesias"].tap()

  20. WE TEST FROM THE USER'S VIEWPOINT

  21. BUT...

  22. NON-UI STUFF (THAT DEPENDS ON THE VIEWS LIFECYCLE) IS ALSO

    TAKING PLACE
  23. ! NETWORKING

  24. !THAT REFLECTS ON UI API INTERACTION !THAT DOESN'T REFLECT ON

    UI ANALYTICS
  25. API INTERACTION CAN BE TESTED WITH ACCEPTANCE TESTS

  26. let app = XCUIApplication() app.launch() app.buttons["Stream"].tap() //-----> REQUEST SENT waitForContent(timeout:

    5) let enriqueCell = app.tables.staticTexts["Enrique Iglesias"] enriqueCell.tap() // -----> REQUEST :+1:
  27. BUT ANALYTICS...

  28. let app = XCUIApplication() app.launch() app.buttons["Stream"].tap() //-----> SCREEN EVENT SENT

    let enriqueCell = app.tables.staticTexts["Enrique Iglesias"] enriqueCell.tap() // -----> WAS IT REALLY SENT?
  29. THIS IS EVENT IS NOT SENT

  30. THIS IS EVENT IS NOT SENT THIS EVENT IS SENT

    WITH WRONG PARAMETERS
  31. WHAT CAN I DO THEN? ! (ANALYTICS MIGHT BE CRITICAL

    FOR YOUR BUSINESS !)
  32. SZIMPLA NETWORK TESTING IN SWIFT GITHUB.COM/PEPIBUMUR/SZIMPLA

  33. None
  34. ONLY ! STEPS

  35. 1. RECORD THE SNAPSHOT

  36. class AppUITests: XCTestCase { func testDefault() { try! Szimpla.Client.instance.start() let

    app = XCUIApplication() app.buttons["Navigate"].tap() try! Szimpla.Client.instance.record(path: "CMDUConf.json") } }
  37. 2. VALIDATE THE SNAPSHOT

  38. [ { "url": "https://api.soundcloud.com/tracks/1235123", "parameters": {}, "body": {} } ]

  39. [ { "url": "https://api.soundcloud.com/tracks/[0-9]+", "parameters": {}, "body": {} } ]

  40. 3. UPDATE THE TEST

  41. class AppUITests: XCTestCase { func testDefault() { try! Szimpla.Client.instance.start() let

    app = XCUIApplication() app.buttons["Navigate"].tap() try! Szimpla.Client.instance.validate(path: "CMDUConf.json") } }
  42. LIVE DEMO ! "

  43. SPANSHOT APPROACH (INSPIRED BY FACEBOOK SNAPSHOT TESTING)

  44. SUPPORTS CUSTOM VALIDATORS

  45. public protocol Validator { func validate(recordedRequests recordedRequests: [Request], localRequests: [Request])

    throws }
  46. SUPPORTS CUSTOM FILTERS

  47. public protocol RequestFilter { func include(request request: Request) -> Bool

    }
  48. ANALYTICS TEAM CAN VALIDATE THE SNAPSHOTS IT'S A JSON FILE!

    ! !
  49. REFERENCES > Szimpla > Facebook Snapshot Testing > Swifter HTTP

    Server > Unsplash
  50. GRÀCIES ! QUESTIONS? SLIDES (SPEAKERDECK) - HTTP://BIT.LY/29XRQ7M PEPIBUMUR - PEPIBUMUR@GMAIL.COM