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

Better UI Testing with Swift Robots - Mobile Er...

Better UI Testing with Swift Robots - Mobile Era Meetup 2017

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

Includes a whole bunch of stuff towards the end I wasn't actually able to get to in the talk around #file and #line, as well as some of the gotchas of trying to make all the protocols talk to each other properly.

Please feel free to reach out on twitter to @designatednerd if you have follow-up questions.

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

Ellen Shapiro

October 04, 2017
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. ! ! ! ! ! ! ! ! ! -----------------------------------------

    Better UI testing with Swift Robots Mobile Era Community Meetup | Oslo | October 2017 @designatednerd | designatednerd.com | justhum.com ----------------------------------------- ! ! ! ! ! ! ! ! !
  2. KIF

  3. ! ! ! ! ! ! ! ! ! -------------------------

    ROBOTS ------------------------- ! ! ! ! ! ! ! ! !
  4. KIF

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

    GoCubsKIFTests: KIFTestCase { ✅ class GoCubsEarlGreyTests: XCTestCase {
  6. Using the protocol instead: !!!!!!!!!!!!!!!!!!!!!!!!!!!! class GoCubsXCUITests: XCTestCase, RobotTests {

    class GoCubsKIFTests: KIFTestCase, RobotTests { class GoCubsEarlGreyTests: XCTestCase, RobotTests { !!!!!!!!!!!!!!!!!!!!!!!!!!!!
  7. Using @testable import: ❌ class GoCubsXCUITests: XCTestCase, RobotTests { ✅

    class GoCubsKIFTests: KIFTestCase, RobotTests { ✅ class GoCubsEarlGreyTests: XCTestCase, RobotTests {
  8. Obligatory Summary Slide! Robots will help you: - Separate what

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

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

    what from how - Keep your tests readable - Swap out the underlying implementation FREE ADVICE:
  11. 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.
  12. 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/
  13. 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