Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

CI in the mobile world

5,260 views

Published on

Codemash 2012 presentation

Published in: Technology

CI in the mobile world

  1. 1. CI in the Mobile WorldGodfrey NolanRIIS LLCgodfrey@riis.com
  2. 2. Agenda• What is CI• Benefits of CI in Mobile World• CI Configuration • Android • iPhone• Still a work in progress • Perfecto Mobile • Test Flight App • Executable Requirements
  3. 3. Spam #1• RIIS LLC • Based in Southfield, MI• Mobile Development • Fandango • DTE Outage Maps • BroadSoft Front Office Assistant• Other Clients • BondDesk • Comerica • BCBSM
  4. 4. Spam #2
  5. 5. What is CI?• Automate everything • Soup to nuts • Build, test and deploy• Build as often as possible • Build early, build often • Typically on every checkin • Alternatively nightly builds• Practice, practice, practice
  6. 6. What is CI?• Automate …. • Builds • Unit testing • Functional testing. • Mobile Device Testing • Code Coverage • Deployment
  7. 7. Benefits of CI• Fewer Errors • iPhone vs. Android story• Faster Feedback• Repeatable and Reliable• No more manual testing • Cheaper• Built in regression testing
  8. 8. Benefits of CI in a Mobile World• Less complex • Mobile in its infancy • Typically smaller projects and teams• Lots of CI mobile plugins available• Easy deployment options • Testflight App (iPhone) • Email apk (Android)• Too many Android devices to manually test • Automated Device testing is the holy grail
  9. 9. Mobile Device Testing
  10. 10. Goal
  11. 11. Goal
  12. 12. It’s all about your perspective
  13. 13. CI Configuration Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  14. 14. CI Server• Jenkins is de-facto industry standard• Currently the best choice • Number of plugins • Ease of use• Good for both Android and iPhone apps.
  15. 15. CI Server• Download from http://jenkins-ci.org/.• "java -jar jenkins.war" from cmd line• load Jenkins in browser at http://localhost:8080• RIP Hudson
  16. 16. CI Server
  17. 17. CI Server• Under Manage Jenkins, Configure System. • Add ant, JDK, and android SDK paths• Under Manage Jenkins, Plugin Manager. • Install XCode, GitHub and TestFlight
  18. 18. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  19. 19. Source Code Repository• Provides • Safety • Version Control etc.• Subversion (SVN) or GitHub • SVN for the Android project • GitHub for iPhone project
  20. 20. Android and iPhone projects
  21. 21. SVN• Create a new project on your SVN host
  22. 22. SVN• Using tortoise svn simply right click and say import.• Note that using the standard trunk tags and branches of svn will force you to specify your build.xml location in Jenkins because it will not be in the project root.
  23. 23. GitHub• Download Git from github.com• Create a new ssh key by entering the following command ssh-keygen –t rsa –C “your-email”• Enter a passphrase when prompted.• Click on GitHub.com account settings, SSH public keys, and click add a SSH Key.• Copy the contents of the id_rsa.pub and hit add key.
  24. 24. GitHub Cont.• To create a repository • Click create a repository on github.com • Fill in the requested fields. • git init in source code dir • git add (file(s) to be added) • git commit –m “message” • git push to push to GitHub
  25. 25. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  26. 26. Creating a Android Test Project• Create a new project AndroidCIDemo and select free style project.
  27. 27. Configuring a Android TestProject• Enter SVN details• Jenkins will alert you if it cannot access the URL• Be sure to enter credentials correctly
  28. 28. Configuring a Android Test ProjectCont.• Under the Build tab • Add commands to build/run the project. • Click on Add build step and select Execute shell. • Run android update project must be run in order to create the local.properties file.[path_to_android_sdk]/tools/android update project –p./[path_to_build.xml]• If android tools is already on your path and the build.xml file is in root than the command would be:Android update project –p ./• Add another build step Invoke Ant and add the target debug.• If build.xml file not in root hit advanced and specify its location in the build file field.
  29. 29. BuildNow build the project and hopefully it runs with no errors.
  30. 30. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  31. 31. Unit Tests• For unit tests in Android use built in JUnit framework.
  32. 32. Functional Tests• For Android Functional tests use Robotium• To implement Robotium all you have to do is add it to your test projects build path.• GUI based, i.e. brittle
  33. 33. Modifications to the Android Project• Both Unit and Functional tests are run in the same way.• To run android tests run an emulator during the build.• Under build environment choose Run an Android emulator during build. If you have already created an emulator using the android avd than you can choose to run that here, otherwise choose run emulator with properties.• Specify the OS version, Screen density and Screen resolution• Uncheck the Show emulator window box under Common emulator options to run headless.
  34. 34. Modifications Cont.• Add another Execute shell command: [path_to_android_sdk]/tools/android update test-project –p ./[path_to_test_project] –m ./[path_to_main_project].• And change the ant target to debug install test (don’t forget to change the build file if its not in root).
  35. 35. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  36. 36. Multi Configuration Job• For multiple device testing create matrix jobs • Specify variables to run multi test combinations • Run multiple emulators to make sure the app behaves same across different devices
  37. 37. Configuration Matrixes• Create a new project in Jenkins and choose matrix configuration job.• Same setup except we have to add one or more configuration matrixes.
  38. 38. Configuration Matrixes Cont.• Under the Configuration Matrix tab choose add axis.• Jenkins will than ask for a name and values. For example you can choose to create an emulator for different OS versions and screen densitys.• This matrix runs job on four different emulators.
  39. 39. Configure the Emulator• Now use variables instead of hard coded values.
  40. 40. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  41. 41. Android Deployment• Manage Jenkins->manage plugins.• Download email-extension plugin
  42. 42. Email Configuration• Go to email notification tab and check the box.• Choose a recipient, subject, and message. Under attachments give it the argument **/*.apk• Add trigger on success to choose who it’s sent to.
  43. 43. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  44. 44. Creating a iPhone Test Project• Create a new job IPhoneCIDemo with the option build free style
  45. 45. Configuring the IPhone TestProject• Go to the source control tab and select GitHub.• Copy your GitHub into Repository URL field• Specify a branch if not in the default branch.
  46. 46. Configuring the IPhone Test ProjectCont.• Go to the build tab and add a new build step XCode.• Change the XCode target to the target you want to build, and supply XCode project directory and file if not in root.• Fill in the XCode SDK field and change the Configuration field to default or debug.
  47. 47. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  48. 48. iPhone Unit Tests• Use standard OCunit testing framework.• Jenkins uses Christian Hedlin’s Ocunit2junit ruby script • Converts the Xcode OCunit tests to JUnit tests. • Cannot run any tests that touch the UI.
  49. 49. Modifications to the IPhone Project • Remove test host values under the build settings • Add a new build step:xcodebuild -target yourtarget -configuration Debug -sdkiphonesdk | [path_to_ruby_script]/ocunit2junit.rb • Choose publish junit test results and give it the value test- reports/*.xml
  50. 50. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  51. 51. iOS Functional Tests• Use FoneMonkey to run functional tests from CI.• Create automated tests by recording scripts and adding verification steps• Brittle GUI testing again 
  52. 52. FoneMonkey• To implement FoneMonkey first create a new target by duplicating the primary target.• Download the FoneMonkey Zip File and add it to the new target• Under the build phases tab of the FoneMonkey target go to the link with binary with libraries tab.• Click on the + button and add the CoreGraphics.framework and QuartzCore.framework.• You will also need to add the libxml2.dylib and SenTestingKit.framework• Lastly On the Build Settings tab, scroll down to the Linking section and set Other Linker Flags to -all_load
  53. 53. FoneMonkey Cont.• To be able to run FoneMonkey from the command line without having to start Xcode we need to create a TestRunner• Create a new target off of your FoneMonkey target• Add a run script to the TestRunner target under build phasesexport FONEMONKEY_HOME=~/[Location_of_Fone_Monkey]export FAMILY=[iphone|ipad]export LOG_FILE="$PROJECT_DIR/$TARGETNAME.log“export FONEMONKEY_ENV=$FONEMONKEY_HOME/FoneMonkeyRunner.plist rm -f "$LOG_FILE"$FONEMONKEY_HOME/bin/iphonesim launch "$CODESIGNING_FOLDER_PATH" -verbose -sdk$IPHONEOS_DEPLOYMENT_TARGET -family $FAMILY -stderr “ $LOG_FILE" -env"$FONEMONKEY_ENV“• You can now run this target from the command line and it will run your FoneMonkey tests for you.
  54. 54. FoneMonkey• The command to run the FoneMonkey TestRunner is xcodebuild –target TestRunnerTargetName –sdkiPhonesimulatorsdk –configuration Debug
  55. 55. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  56. 56. iPhone Deployment• Use Test Flight App• Over the air beta testing• Test Flight app Jenkins plugin doesn’t work• But…all is not lost • Add a new build step and choose Xcode • Fill in the normal fields and choose to build IPA and unlock keychain as well. • Add keychain password.
  57. 57. iPhone Deployment • Add a build step execute shell and add the following commands:cd $WORKSPACE/build/Release-iphoneos/ curlhttp://testflightapp.com/api/builds.json-F file=@[IPA_FILE_NAME] -Fapi_token=[API_TOKEN] -F team_token=[TEAM_TOKEN] -Fnotes=This is an auto deploy build from Jenkins! -F notify=True -Fdistribution_lists=[DISTRIBUTION_LIST]• Team token and api token can be gotten from your testflight account
  58. 58. Requirements for CI Android IPhone Requirement CI Server Source Code Repository Project Build Unit Testing Functional Testing Mobile Device Testing Deployment
  59. 59. Conclusion• Work in Progress • Executable Requirements • Perfecto Mobile • Test Flight App• Demo• Followup • github.com/RIIS/RIIS-codemash.git • godfrey@riis.com • Android Application Testing Guide
  60. 60. Thanks• RIIS • Derek Verlee • David Armstrong • Brad Dunlap• Nayan Hajratwala

×