Slide 1

Slide 1 text

Climbing the Testing Pyramid in iOS Chris Trevarthen (@malusman) & Jake Payton (@JakePayton) https://github.com/ctrevarthen/selfconf-wunderground-objc 1

Slide 2

Slide 2 text

Why test • Contract with your code / spec • Assists in refactoring • Documents code • Saves you time that you don’t have • In the future, where we are from, it is seen as malpractice not to test 2

Slide 3

Slide 3 text

The pyramid • Functional UI • Service Integration • Unit Tests 3

Slide 4

Slide 4 text

Questions • What about TDD? Do I have to test first? • What about test coverage? What should our goal be? • How much longer does it take? How do I get time to do this? • Why do I need QA? • Why can’t I just write all Functional tests? What’s the right mix of tests? • Test Ice Cream Cone is bad m’kay 4

Slide 5

Slide 5 text

Unit Tests • Lots of options • Differences in output? • How it plays with Xcode • Advantages/ Disadvantages 5

Slide 6

Slide 6 text

XCTest • Apple’s thing • Style of the tests aren't as sexy, but it plays very nice with Xcode. (i.e. run individual tests) • Performance Testing is supported, kinda neat (measureBlock) 6

Slide 7

Slide 7 text

Kiwi • Pretty syntax, based on ruby RSpec style • great options for mocking, stubbing, spying, etc • Doesn't play as nice as XCTest in xCode, can’t run individual tests BUT you can run individual test suites with ⌘ + option + control + U • Derived Data 7

Slide 8

Slide 8 text

Specta • Similar to Kiwi using the RSpec BDD syntax but more of a customizable shell for writing tests than a drop-in replacement 8

Slide 9

Slide 9 text

Quick • Testing framework for Swift language • Similar to RSpec style test, uses Nimble for matching 9

Slide 10

Slide 10 text

iOS testing is hard • To explain • Easier to show • Here’s an app we’ll add tests to 10

Slide 11

Slide 11 text

Sunny Daze • Simple app functionality • Takes user input • Makes API calls • Extracts info • Displays info to user 11

Slide 12

Slide 12 text

The pyramid • WeatherResultsViewController • WeatherService • LocationEntryViewController 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

How to write brittle tests • Test implementation • Rely on outside state • Test strings that will change • Real network calls • How to make tests less brittle - stubbing/mocking 14

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

Customizing your unit test framework • Can be further customized with these add-on libraries for mocking, stubbing, etc. • Idea here is that there are lots of ways to make testing work best for you 16

Slide 17

Slide 17 text

Integration Tests • No special framework here, just an approach. • What you are testing is your ability to make requests and connections • You can use your preferred unit testing framework 17

Slide 18

Slide 18 text

Integration Tests • But you will want to do these in a separate scheme so that you control when they occur • The are slow, expensive, and most likely talking to a real server which possible undesired outcomes • Tools like RunScope will test your endpoints regularly and send failure reports • OHHTTPStubs intercept network calls and injects your own data 18

Slide 19

Slide 19 text

Functional Acceptance Tests • Most difficult to do, and keep doing • Testing the UI of your app and the resulting user experience • Works well to augment the manual testing by saving immense amounts of time and effort • Good for business/stakeholder to be able to define the test conditions in a human readable manner • User facing scenarios 19

Slide 20

Slide 20 text

KIF • “Keep It Functional” • KIF-Kiwi • Or is it Kiwi-KIF? • "tap this view," "enter text into this view," and "wait for this view” 20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

KIF • Can run right in Xcode • Need to manually clean up between tests • Good solution for Devs • Beware Xcode 6.3.x 22

Slide 23

Slide 23 text

Frank / Calabash • Uses cucumber • “Features” are written in plain English • “Steps” are written in Ruby • (Supposedly) reusable across platforms 23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

Frank / Calabash • Build-to-test cycle is disconnected • Good solution for BA/QA (with Dev help) • Cleans up between tests (slower) • Beware Xcode 6.3.x 25

Slide 26

Slide 26 text

UIAutomation* • UIAutomation • Apple’s thing • Subliminal • XCTest/OCTest wrapper for UIAutomation • Appium • Uses Selenium’s WebDriver • Write tests in PHP, Java, Ruby, Node.js 26

Slide 27

Slide 27 text

Serving Suggestion • Functional UI: 10% • Service Integration 20% • Unit Tests 70% 27

Slide 28

Slide 28 text

28