Ci for i-os-codemash-01.2013

2,170 views

Published on

CI for iOS. CodeMash version.

Published in: Technology

Ci for i-os-codemash-01.2013

  1. 1. CI for iOS:do more while you sleep Kevin Munc – @muncman Method Up LLC [MU]
  2. 2. CI?
  3. 3. For iOS?
  4. 4. Pain
  5. 5. Pain & Suffering
  6. 6. It can be done• Start with the basics • Xcode and the command line • Version control and CI server• Script it, run it, schedule it
  7. 7. Tip #1
  8. 8. Jenkins• http://jenkins-ci.org/• Mac installer or via homebrew• Many alternatives• Many plugins
  9. 9. Tip #1.1
  10. 10. How many Simulators does it take to break a build?
  11. 11. A CI server gives you:
  12. 12. A CI server gives you: Automation
  13. 13. A CI server gives you: Automation Feedback
  14. 14. A CI server gives you: Automation fu l! er ondW Feedback
  15. 15. A CI server gives you: Automation nd ) i s fu l! f m ap er e o er n ond ac tt Pe beW Feedback (for
  16. 16. Requirement: OS X
  17. 17. Requirement: OS X• macminicolo.net• hosted-ci.com• cisimple.com• macincloud.com• hostmyapple.com• macminivault.com• xcloud.me
  18. 18. Requirement: OS X• macminicolo.net• hosted-ci.com t ni ght,• cisimple.com un a to r ac, dul e CI n M• macincloud.com Or sche your ow ep... on u sle e yo• hostmyapple.com whil• macminivault.com• xcloud.me
  19. 19. Securitysudo /usr/sbin/DevToolsSecurity --enable
  20. 20. Securitysudo xcodebuild -license
  21. 21. 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
  22. 22. 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
  23. 23. Tip #2
  24. 24. Avoid this error from Xcode RunPlatformUnitTests: warning: Skipping tests;the iPhoneSimulator platform does not currently support application- hosted tests (TEST_HOST set).
  25. 25. The culprit/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
  26. 26. The workaround(s)
  27. 27. Xcode Plugin• https://wiki.jenkins-ci.org/display/JENKINS/Xcode+Plugin• Specify provisioning profile• Keychain access• Signed IPA
  28. 28. Xcode Plugin• Recommended xcodebuild arguments: • GCC_SYMBOLS_PRIVATE_EXTERN=NO • COPY_PHASE_STRIP=NO • Allows test bundle to link with Release build symbols
  29. 29. Signing with the Plugin
  30. 30. Signing with the Plugin
  31. 31. Signing with the Plugin
  32. 32. Tip #3
  33. 33. 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
  34. 34. xcodebuildxcodebuild clean build
  35. 35. Tip #4
  36. 36. Be specific withxcodebuild options
  37. 37. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  38. 38. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  39. 39. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  40. 40. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  41. 41. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  42. 42. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  43. 43. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  44. 44. xcodebuildxcodebuild -scheme SOLID -target SOLID -configuration Debug -arch i386 -sdk iphonesimulator clean build
  45. 45. Tip #5
  46. 46. Specify Alternate Output Locations• Don’t rely on Xcode’s cryptic locations• This will make your scripts easier to manage
  47. 47. # Build location for Instruments test runs.CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIRxcodebuild ... CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR clean build
  48. 48. # Build location for Instruments test runs.CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIRxcodebuild ... CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR clean build
  49. 49. # Build location for CI test runs.CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIRxcodebuild ... CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR clean build
  50. 50. Demo
  51. 51. Tip #6
  52. 52. 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)
  53. 53. Tip #7
  54. 54. Test against multiple SDKs-sdk iphonesimulator5.0-sdk iphonesimulator5.1-sdk iphonesimulator6.0
  55. 55. 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”
  56. 56. OCUnit
  57. 57. Other Related Tools
  58. 58. Other Related Tools• OCMock • XcodeTest• OCMockito • AutoBuild• OCHamcrest • xcodeproj (CocoaPods)• Expecta • Circle?• TinyMock • Simon?• LRMocky • ios-maven-plugin• OCUnit2JUnit • Ceedling• OCUnitReport • XcodeCoverage• Kicker • JMRTestTools• xcodebuild-rb • Nocilla• xcodearchive • OHHTTPStubs
  59. 59. OCUnit Alternatives• Kiwi• Cedar• OCDSpec• C++ Automated Test Cases in Headers (CATCH)• Objective-Shoulda• Specta
  60. 60. Tip #8
  61. 61. OCUnit2JUnit for Test Results• ocunit2junit.rb• https://github.com/ciryon/OCUnit2JUnit• Converts output to JUnit format for easier transformation to HTML
  62. 62. UIAutomation
  63. 63. Other UIAutomation Tools• tunup_js • ios-sim• jasmine-iphone • ios-sim-locale• uiautomation-jasmine- • iphonesim iphone • ui-auto-monkey• Bwoken • ui-screen-shooter• Zucchini Framework • uiautomation-rb?• WaxSim
  64. 64. UIAutomation Alternatives• Frank • Objective C Slim (ocslim)• (iCuke) • AutomationKit• KIF • Sikuli• Calabash • MonkeyTalk (formerly• UISpec FoneMonkey)• Bromine • Plus other commercial tools, such as Telerik Test Studio for iOS
  65. 65. Tip #9
  66. 66. PListBuddy is Your Buddy/usr/libexec/PlistBuddy
  67. 67. Tip #10
  68. 68. Always quit the simulator• killall • killall -m -KILL "iPhone Simulator"• AppleScript • osascript -e tell app "iPhone Simulator" to quit
  69. 69. Tip #11
  70. 70. Use Jonathan Penn’s AutomationExamplehttps://github.com/jonathanpenn/AutomationExample
  71. 71. Demo
  72. 72. More?
  73. 73. Code Coverage “Risk coverage”
  74. 74. Coverage Tools• gcov • GCC’s coverage tool• GUIs for gcov • LCOV (HTML) • CoverStory (Mac app)• ocov?
  75. 75. Tip #12
  76. 76. gcovr forCoverage AutomationProduces Cobertura-formatted output from gcov data
  77. 77. Tip #12.1
  78. 78. Enable Test Coverage
  79. 79. Static Analysis• Clang• http://clang-analyzer.llvm.org/• scan-build
  80. 80. Tip #13
  81. 81. Symbolic linkscan be your ally
  82. 82. Avoid scan-build Pain sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/ XcodeDefault.xctoolchain/usr/lib/arc/ libarclite_iphonesimulator.a /usr/lib/arc/libarclite_iphonesimulator.a
  83. 83. What abouttest build deployment?
  84. 84. Tip #14
  85. 85. Use TestFlight• testflightapp.com• OTA deployment• SDK for more features• Free!!
  86. 86. TestFlight• Web UI• Desktop App• REST API• Jenkins Plugin
  87. 87. 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...
  88. 88. TestFlight Config• API Token and Team Token• Need a signed IPA• They get an email with a link for OTA installation!
  89. 89. Tip #15
  90. 90. 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)
  91. 91. TestFlight Plugin
  92. 92. TestFlight Script
  93. 93. Deployment
  94. 94. Deployment
  95. 95. Q: Once you have a nightly job to build,unit test, sign an IPA and deploy it to QA, what’s next?
  96. 96. 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.
  97. 97. Documentation• Appledoc• Doxygen• HeaderDoc
  98. 98. DocSets
  99. 99. Appledoc
  100. 100. Doxygen
  101. 101. Tip #16
  102. 102. Don’t stop there!
  103. 103. Other Goodies
  104. 104. 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
  105. 105. 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
  106. 106. Tip #n
  107. 107. 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
  108. 108. Thank you!• CodeMash organizers• CodeMash sponsors• and YOU! [MU]
  109. 109. Thank you!• CodeMash organizers• CodeMash sponsors• and YOU! Questions? [MU]

×