Better UI Testing with Swift Robots - CocoaConf Next Door San Jose, June 2017

Better UI Testing with Swift Robots - CocoaConf Next Door San Jose, June 2017

My deck on using the Robot pattern for more readable, more flexible tests in Swift.

Codez: https://github.com/designatednerd/GoCubs

C4861b1dfdf3bbb21faec4a1acdf183d?s=128

Ellen Shapiro

June 06, 2017
Tweet

Transcript

  1. 1.

    ! ! ! ! ! ! ! ! ! -----------------------------------------

    Better UI testing with Swift Robots CocoaConf Next Door | San Jose, CA | June 2017 @designatednerd | spothero.com | justhum.com ----------------------------------------- ! ! ! ! ! ! ! ! !
  2. 7.

    KIF

  3. 8.
  4. 11.
  5. 13.

    ! ! ! ! ! ! ! ! ! -------------------------

    ROBOTS ------------------------- ! ! ! ! ! ! ! ! !
  6. 14.
  7. 15.
  8. 16.
  9. 19.
  10. 20.
  11. 22.
  12. 24.
  13. 25.
  14. 26.
  15. 30.
  16. 31.
  17. 32.
  18. 34.
  19. 36.
  20. 41.
  21. 43.
  22. 44.
  23. 45.
  24. 46.

    KIF

  25. 47.
  26. 48.
  27. 49.
  28. 50.
  29. 51.
  30. 52.
  31. 53.
  32. 54.
  33. 55.
  34. 57.
  35. 58.
  36. 59.
  37. 60.
  38. 61.
  39. 62.
  40. 63.
  41. 65.
  42. 66.

    Subclassing XCTest directly: ✅ class GoCubsXCUITests: XCTestCase { ❌ class

    GoCubsKIFTests: KIFTestCase { ✅ class GoCubsEarlGreyTests: XCTestCase {
  43. 68.
  44. 69.

    Using the protocol instead: !!!!!!!!!!!!!!!!!!!!!!!!!!!! class GoCubsXCUITests: XCTestCase, RobotTests {

    class GoCubsKIFTests: KIFTestCase, RobotTests { class GoCubsEarlGreyTests: XCTestCase, RobotTests { !!!!!!!!!!!!!!!!!!!!!!!!!!!!
  45. 70.
  46. 71.
  47. 72.
  48. 74.

    Using @testable import: ❌ class GoCubsXCUITests: XCTestCase, RobotTests { ✅

    class GoCubsKIFTests: KIFTestCase, RobotTests { ✅ class GoCubsEarlGreyTests: XCTestCase, RobotTests {
  49. 75.
  50. 76.
  51. 79.

    Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable
  52. 80.

    Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable - Swap out the underlying implementation
  53. 81.

    Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable - Swap out the underlying implementation FREE ADVICE:
  54. 82.

    Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable - Swap out the underlying implementation FREE ADVICE: - Giving techniques cool names makes it way more likely people will steal use them.
  55. 83.

    Links! — Earl Grey: https://github.com/google/EarlGrey — KIF: https://github.com/kif-framework/KIF — Jake

    Wharton on Kotlin Robots: https://realm.io/ news/kau-jake-wharton-testing-robots/ — Joe Masilotti on XCTest Helpers: http:// masilotti.com/xctest-helpers/
  56. 85.

    Photo Credits! — "Earl Grey" by Ana Ulin https://www.flickr.com/ photos/anaulin/164424396/

    — "maybe now I'll get my texts" by frankieleon https:// www.flickr.com/photos/armydre2008/3935008214 — Cubs Winning The World Series, by Matt Slocum, AP https://www.nytimes.com/2016/11/03/sports/ baseball/chicago-cubs-beat-cleveland-indians- world-series-game-7.html