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

Better UI Testing With Swift Robots - Forward Swift, San Francisco, March 2017

Better UI Testing With Swift Robots - Forward Swift, San Francisco, March 2017

Video:
https://www.youtube.com/watch?v=flZDWc25paw

[Apologies for talking reallydamnedfast, I thought my slot was way longer than it actually was. Oops!]

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
PRO

March 02, 2017
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. ! ! ! ! ! ! ! ! ! !

    Better UI testing with Swift Robots Forward Swift | San Francisco, CA | March 2017 @designatednerd | spothero.com | justhum.com ! ! ! ! ! ! ! ! ! !
  2. Preamble: UI vs. Unit Tests

  3. UI Testing Options

  4. KIF

  5. XCUI

  6. Earl Grey

  7. So which framework should you use?

  8. None
  9. You can use this technique with any or every UI

    testing framework
  10. ! ! ! ! ! ! ! ! ! ROBOTS

    ! ! ! ! ! ! ! ! !
  11. None
  12. None
  13. None
  14. None
  15. Sample Code https://github.com/designatednerd/GoCubs

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

  17. None
  18. KIF XCUI

  19. With DRY refactoring:

  20. None
  21. With Robots:

  22. Separate the What from the how

  23. More Composable test code

  24. None
  25. None
  26. None
  27. ROBOTS * - sometimes known as controllers

  28. How do we steal adapt this idea for Swift?

  29. Protocols!

  30. None
  31. KIF

  32. XCUI

  33. Earl Grey

  34. None
  35. KIF XCUI

  36. None
  37. None
  38. None
  39. Earl Grey

  40. Earl Grey

  41. Some gotchas with multiple variations

  42. None
  43. Subclassing XCTest directly: ✅ class GoCubsXCUITests: XCTestCase { ❌ class

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

  45. None
  46. Using the protocol instead: !!!!!!!!!!!!!!!!!!!!!!!!!!!! class GoCubsXCUITests: XCTestCase, RobotTests {

    class GoCubsKIFTests: KIFTestCase, RobotTests { class GoCubsEarlGreyTests: XCTestCase, RobotTests { !!!!!!!!!!!!!!!!!!!!!!!!!!!!
  47. None
  48. None
  49. None
  50. Using @testable import:

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

    class GoCubsKIFTests: KIFTestCase, RobotTests { ✅ class GoCubsEarlGreyTests: XCTestCase, RobotTests {
  52. None
  53. None
  54. Obligatory Summary Slide!

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

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

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

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

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

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