Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Preamble: UI vs. Unit Tests

Slide 3

Slide 3 text

Unit Tests Testing small pieces of independent code

Slide 4

Slide 4 text

UI Tests Try to use your application like a customer

Slide 5

Slide 5 text

UI Tests Try to use your application like a customer

Slide 6

Slide 6 text

UI Testing Frameworks

Slide 7

Slide 7 text

KIF

Slide 8

Slide 8 text

XCUI

Slide 9

Slide 9 text

Earl Grey

Slide 10

Slide 10 text

So which framework should you use?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

! ! ! ! ! ! ! ! ! ------------------------- ROBOTS ------------------------- ! ! ! ! ! ! ! ! !

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Separate the What from the how

Slide 18

Slide 18 text

Separate the What from the how

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

How can I steal adapt this idea for iOS?

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

ಠ_ಠ wtf does that mean?

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

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

K I F

Slide 31

Slide 31 text

X C U I

Slide 32

Slide 32 text

With DRY refactoring: KIF XCUI

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

With Robots:

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

ROBOTS * - aka controllers

Slide 37

Slide 37 text

More Composable test code

Slide 38

Slide 38 text

How can I steal improve this idea for Swift?

Slide 39

Slide 39 text

Protocols!

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

A brief interlude about #file and #line

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

ANYWAY

Slide 45

Slide 45 text

KIF

Slide 46

Slide 46 text

XCUI

Slide 47

Slide 47 text

Earl Grey

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

KIF XCUI

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Earl Grey

Slide 54

Slide 54 text

Earl Grey

Slide 55

Slide 55 text

How does this technique scale for testing larger apps?

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Protocol-Oriented Gotchas

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

MOAR PROTOCOLS!

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Using @testable import:

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Obligatory Summary Slide!

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 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 79

Slide 79 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 80

Slide 80 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 81

Slide 81 text

Question Time!

Slide 82

Slide 82 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