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

CI for iOS

muncman
January 11, 2013

CI for iOS

CodeMash version of my Continuous Integration for iPhone and iPad talk.

muncman

January 11, 2013
Tweet

Other Decks in Programming

Transcript

  1. CI for iOS: do more while you sleep Kevin Munc

    – @muncman Method Up LLC [MU]
  2. CI?

  3. It can be done • Start with the basics •

    Xcode and the command line • Version control and CI server • Script it, run it, schedule it
  4. Requirement: • macminicolo.net • hosted-ci.com • cisimple.com • macincloud.com •

    hostmyapple.com • macminivault.com • xcloud.me OS X Or schedule CI to run at night, on your own Mac, while you sleep...
  5. Credentials • The CI server needs access to your repository

    • SSH key • The CI server needs Keychain credentials if you want to sign your builds • Developer certificate and profiles
  6. Keychain • Export and Import using Keychain Access app •

    Keys and Certificates • Or use the command line: • sudo security import /path/to/distribution.cer -k /Library/Keychains/ System.keychain • sudo security import /path/to/distribution.p12 -k /Library/Keychains/ System.keychain • Don’t forget about provisioning profiles • Troubleshooting: http://tinyurl.com/iOSDevToolTroubles
  7. Avoid this error from Xcode RunPlatformUnitTests: warning: Skipping tests; the

    iPhoneSimulator platform does not currently support application- hosted tests (TEST_HOST set).
  8. Prefer Scripts over CI Plugins • More flexibility • More

    resilient to Apple’s changes • More power to adapt and expand (specificity) • Less coupling to the specific CI server type • You can version control the settings easier
  9. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  10. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  11. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  12. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  13. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  14. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  15. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  16. xcodebuild xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration

    Debug \ -arch i386 \ -sdk iphonesimulator \ clean build
  17. Specify Alternate Output Locations • Don’t rely on Xcode’s cryptic

    locations • This will make your scripts easier to manage
  18. # Build location for Instruments test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATION mkdir -p

    $CI_BUILD_DIR xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build
  19. # Build location for Instruments test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATION mkdir -p

    $CI_BUILD_DIR xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build
  20. # Build location for CI test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATION mkdir -p

    $CI_BUILD_DIR xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build
  21. Ensure Return Codes • If the tool you are invoking

    in your script doesn’t return an exit code indicating pass/fail, it’s up to you. • Unix-friendly 0 (success) or 1 (failure)
  22. Other Tools to Know About • xcode-select (manage xcode path)

    • Overridden by DEVELOPER_DIR • xcrun (find and run dev tools) • ibtool (for Interface Builder files) • /Applications/Xcode.app/Contents/Developer/usr/bin/ • Variables in Xcode • “Build Settings Reference”
  23. Other Related Tools • OCMock • OCMockito • OCHamcrest •

    Expecta • TinyMock • LRMocky • OCUnit2JUnit • OCUnitReport • Kicker • xcodebuild-rb • xcodearchive • XcodeTest • AutoBuild • xcodeproj (CocoaPods) • Circle? • Simon? • ios-maven-plugin • Ceedling • XcodeCoverage • JMRTestTools • Nocilla • OHHTTPStubs
  24. OCUnit Alternatives • Kiwi • Cedar • OCDSpec • C++

    Automated Test Cases in Headers (CATCH) • Objective-Shoulda • Specta
  25. Other UIAutomation Tools • tunup_js • jasmine-iphone • uiautomation-jasmine- iphone

    • Bwoken • Zucchini Framework • WaxSim • ios-sim • ios-sim-locale • iphonesim • ui-auto-monkey • ui-screen-shooter • uiautomation-rb?
  26. UIAutomation Alternatives • Frank • (iCuke) • KIF • Calabash

    • UISpec • Bromine • Objective C Slim (ocslim) • AutomationKit • Sikuli • MonkeyTalk (formerly FoneMonkey) • Plus other commercial tools, such as Telerik Test Studio for iOS
  27. Always quit the simulator • killall • killall -m -KILL

    "iPhone Simulator" • AppleScript • osascript -e 'tell app "iPhone Simulator" to quit'
  28. Coverage Tools • gcov • GCC’s coverage tool • GUIs

    for gcov • LCOV (HTML) • CoverStory (Mac app) • ocov?
  29. TestFlight Alternatives • HockeyApp • http://hockeyapp.net • Also has a

    Jenkins plugin (forked) • BetaBuilder for iOS • http://www.hanchorllc.com/betabuilder-for-ios/ • More players in this space, esp. for enterprises...
  30. TestFlight Config • API Token and Team Token • Need

    a signed IPA • They get an email with a link for OTA installation!
  31. Protect Your Tokens • API Token & Team Token •

    Keep them out of scripts • Instead, define them in Jenkins (and leverage Jenkins security) • 'Configure System' • 'Global properties' section • Or use the plugin (same parameters)
  32. Q: Once you have a nightly job to build, unit

    test, sign an IPA and deploy it to QA, what’s next?
  33. Q: Once you have a nightly job to build, unit

    test, sign an IPA and deploy it to QA, what’s next? A: Sleeping easy.
  34. Other Goodies • Ensure your site or API is up

    • Scan your code for TODOs and FIXMEs • Get trend reports for lines of code (SLOCCount w/ sloc2html) • Scan for duplicated blocks of code (CPD, Simian, etc.) • Use agvtool (Apple-Generic Versioning Tool) to increment your build number
  35. Still Missing • Cyclomatic Complexity • Coding convention/Style checker •

    Code Formatter • Uncrustify, UniversalIndentGUI • UML Generation • via CLI, as opposed to OmniGraffle (AppleScript?) • ER Diagram from Core Data schema
  36. Sources • Slides: http://www.slideshare.net/muncman • http://blog.carbonfive.com/category/mobile/ • http://www.stewgleadow.com/ • http://lifeandcode.net/

    • http://longweekendmobile.com/blog/ • http://longweekendmobile.com/2011/04/17/xcode4-running-application- tests-from-the-command-line-in-ios/ • http://qualitycoding.org • et cetera