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

Test-Driven Development for iOS

Test-Driven Development for iOS

MobiDevDay 2013 talk on how to use test tools like Kiwi and Calabash to test-drive iOS apps.

0e90de19c7e9572e0746c9761fa75c35?s=128

Chris Trevarthen

May 04, 2013
Tweet

Transcript

  1. Test-Driven Development for iOS Chris Trevarthen Monday, May 6, 13

  2. this guy Monday, May 6, 13

  3. How It All Began (For Me) Monday, May 6, 13

  4. BASIC Monday, May 6, 13

  5. C++ Monday, May 6, 13

  6. Java Monday, May 6, 13

  7. TDD Monday, May 6, 13

  8. Testing Triangle (c) Patrick Wilson Welsh Monday, May 6, 13

  9. iOS Testing - Unit • OCUnit • GHUnit • Kiwi

    Monday, May 6, 13
  10. Kiwi - How to get it • Cocoapods! Monday, May

    6, 13
  11. Kiwi - How to get it Monday, May 6, 13

  12. Kiwi - Project Setup • LogicSpecs • ApplicationSpecs Monday, May

    6, 13
  13. Kiwi - Project Setup Monday, May 6, 13

  14. Kiwi - Spec Format Monday, May 6, 13

  15. Kiwi - Mocking Monday, May 6, 13

  16. Kiwi - Assertions Monday, May 6, 13

  17. Kiwi - Output Monday, May 6, 13

  18. I Have Tests - So What? • How do we

    know we’ve done a good job of testing our code? • How do we know potential problem areas in our code? Monday, May 6, 13
  19. Code Coverage! Monday, May 6, 13

  20. iOS Code Coverage Tools • CoverStory Monday, May 6, 13

  21. iOS Code Coverage Tools • XCodeCoverage (+ lcov) Monday, May

    6, 13
  22. Testing Triangle (c) Patrick Wilson Welsh Monday, May 6, 13

  23. Calabash and Cucumber • Behavior Driven Development • Given -

    When - Then (can be written by anyone in the organization) • Also exists for Android and tests can be reused! Monday, May 6, 13
  24. Calabash - How To Get It • Cocoapods support isn’t

    ready yet :( • It is a Ruby gem, though! • gem install calabash-cucumber • calabash-ios setup (adds Xcode target) • calabash-ios gen (adds features dir) Monday, May 6, 13
  25. Calabash - Setup Monday, May 6, 13

  26. Calabash - The Tests • Features • “As a” -

    “I want” - “So that” • Scenarios • “Given” - “When” - “Then” Monday, May 6, 13
  27. Calabash - The Tests Monday, May 6, 13

  28. Calabash - Running • Launch the new scheme from Xcode

    • “cucumber” • How does it know what to click? Monday, May 6, 13
  29. Calabash - Built-In Steps • Screenshots: “take picture” • Touching:

    “Then I touch the ‘login’ button” • Entering text: “Then I enter ‘text’ into input field number 1” • Waiting: “Then I wait for the ‘login’ button to appear” • Back button: “Then I go back” • Swipes: “Then I swipe left” • Pinch: “Then I pinch to zoom in on ‘myLabel’ ” • Scrolling: “Then I scroll down” • Rotation: “Then I rotate device left” Monday, May 6, 13
  30. Calabash • Command-line tool to query while simulator is running

    • Helps to turn on accessibility tool on phone/simulator Monday, May 6, 13
  31. Next Steps • xctool - Facebook’s alternative build tool -

    and it’s good! • ocunit2junit Monday, May 6, 13
  32. (Re)Sources • Setting up testing in iOS: http://bit.ly/W8DDYd • Setting

    up Calabash for iOS: http://bit.ly/RZdrxr • http://cocoapods.org/ • https://github.com/allending/Kiwi • https://github.com/calabash/calabash-ios • https://github.com/facebook/xctool • https://code.google.com/p/coverstory/ • https://github.com/jonreid/XcodeCoverage • http://jenkins-ci.org/ • http://calaba.sh/ • OCUnit vs. GHUnit: http://bit.ly/dFbTCn • Testing Triangle: http://patrickwilsonwelsh.com/?p=32 Monday, May 6, 13
  33. QUESTIONS? • @malusman • ct@detroitlabs.com Monday, May 6, 13