Slide 1

Slide 1 text

! ! ! ! ! ! ! ! ! ! Better UI testing with Swift Robots Forward Swift | San Francisco, CA | March 2017 @designatednerd | spothero.com | justhum.com ! ! ! ! ! ! ! ! ! !

Slide 2

Slide 2 text

Preamble: UI vs. Unit Tests

Slide 3

Slide 3 text

UI Testing Options

Slide 4

Slide 4 text

KIF

Slide 5

Slide 5 text

XCUI

Slide 6

Slide 6 text

Earl Grey

Slide 7

Slide 7 text

So which framework should you use?

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

You can use this technique with any or every UI testing framework

Slide 10

Slide 10 text

! ! ! ! ! ! ! ! ! ROBOTS ! ! ! ! ! ! ! ! !

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

KIF XCUI

Slide 19

Slide 19 text

With DRY refactoring:

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

With Robots:

Slide 22

Slide 22 text

Separate the What from the how

Slide 23

Slide 23 text

More Composable test code

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

ROBOTS * - sometimes known as controllers

Slide 28

Slide 28 text

How do we steal adapt this idea for Swift?

Slide 29

Slide 29 text

Protocols!

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

KIF

Slide 32

Slide 32 text

XCUI

Slide 33

Slide 33 text

Earl Grey

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

KIF XCUI

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Earl Grey

Slide 40

Slide 40 text

Earl Grey

Slide 41

Slide 41 text

Some gotchas with multiple variations

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Subclassing XCTest directly: ✅ class GoCubsXCUITests: XCTestCase { ❌ class GoCubsKIFTests: KIFTestCase { ✅ class GoCubsEarlGreyTests: XCTestCase {

Slide 44

Slide 44 text

MOAR PROTOCOLS!

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Using @testable import:

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Obligatory Summary Slide!

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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.

Slide 60

Slide 60 text

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/

Slide 61

Slide 61 text

Question Time!

Slide 62

Slide 62 text

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