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. ! ! ! ! ! ! ! ! ! -----------------------------------------

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

  3. Unit Tests Testing small pieces of independent code

  4. UI Tests Try to use your application like a customer

  5. UI Tests Try to use your application like a customer

  6. UI Testing Frameworks

  7. KIF

  8. XCUI

  9. Earl Grey

  10. So which framework should you use?

  11. None
  12. You can use this technique with any or every UI

    testing framework
  13. ! ! ! ! ! ! ! ! ! -------------------------

    ROBOTS ------------------------- ! ! ! ! ! ! ! ! !
  14. None
  15. None
  16. None
  17. Separate the What from the how

  18. Separate the What from the how

  19. None
  20. None
  21. How can I steal adapt this idea for iOS?

  22. None
  23. ಠ_ಠ wtf does that mean?

  24. None
  25. None
  26. None
  27. Sample Code https://github.com/designatednerd/ GoCubs

  28. Sample Code https://github.com/designatednerd/GoCubs

  29. Sample Code https://github.com/designatednerd/GoCubs

  30. None
  31. K I F

  32. X C U I

  33. With DRY refactoring: KIF XCUI

  34. None
  35. With Robots:

  36. None
  37. ROBOTS * - aka controllers

  38. More Composable test code

  39. How can I steal improve this idea for Swift?

  40. Protocols!

  41. None
  42. A brief interlude about #file and #line

  43. None
  44. None
  45. ANYWAY

  46. KIF

  47. XCUI

  48. Earl Grey

  49. None
  50. KIF XCUI

  51. None
  52. None
  53. None
  54. Earl Grey

  55. Earl Grey

  56. How does this technique scale for testing larger apps?

  57. None
  58. None
  59. None
  60. None
  61. None
  62. None
  63. None
  64. Protocol-Oriented Gotchas

  65. None
  66. Subclassing XCTest directly: ✅ class GoCubsXCUITests: XCTestCase { ❌ class

    GoCubsKIFTests: KIFTestCase { ✅ class GoCubsEarlGreyTests: XCTestCase {
  67. MOAR PROTOCOLS!

  68. None
  69. Using the protocol instead: !!!!!!!!!!!!!!!!!!!!!!!!!!!! class GoCubsXCUITests: XCTestCase, RobotTests {

    class GoCubsKIFTests: KIFTestCase, RobotTests { class GoCubsEarlGreyTests: XCTestCase, RobotTests { !!!!!!!!!!!!!!!!!!!!!!!!!!!!
  70. None
  71. None
  72. None
  73. Using @testable import:

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

    class GoCubsKIFTests: KIFTestCase, RobotTests { ✅ class GoCubsEarlGreyTests: XCTestCase, RobotTests {
  75. None
  76. None
  77. Obligatory Summary Slide!

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

    what from how
  79. Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable
  80. Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable - Swap out the underlying implementation
  81. Obligatory Summary Slide! Robots will help you: - Separate what

    what from how - Keep your tests readable - Swap out the underlying implementation FREE ADVICE:
  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.
  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/
  84. Question Time!

  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