Created for 2011 Barcamp #YXE
You will need the following:
- Xcode 4
- Access to a working Jenkins install with the following plugins: Jenkins GIT plugin
- git and a git repo hosted where you and Jenkins can access it
git clone https://github.com/gabriel/gh-unit.git
http://gabriel.github.com/gh-unit/docs/index.html
To build the framework for iOS, run make from within the Project-iOS directory. The framework is in Project-iOS/build/Framework/.
If this opens a Finder window with GHUnitIOS.framework in it you have successfully built GHUnit.
Create a new target in your Xcode project, perhaps named GHUnitTest. This link takes you through it, but we can summarize here.
http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_install_ios_4.html
At this point, you want to get GHUnit into your project.
In the root of your project, create a folder: Vendors
Remember that GHUnitIOS.framework package? Copy that folder into Vendors.
git add Vendors; git commit -m "Vendor directory with GHUnit framework"
You will want to Add Other and browse to your Vendors/GHUnitIOS.framework you copied earlier
Xcode is dumb, so you will have to move that framework to your frameworks folder if you are OCD.
In the build settings for your GHUnitTest target, you need to add two linker flags: -ObjC and -all_load
You will want to use the AppDelegate provided in the GHUnitIOS.framework, "GHUnitIOSAppDelegate"
If you didn't bugger anything up, everything should compile and run.
GHUnit can do all sorts of amazing tests, you can see examples in their docs: http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_testing.html
To do CI with Jenkins you will need to setup some scripts that manage building and testing from the command line. Lucky us, I have included those scripts for you.
Copy the Scripts folder from this repo into the root of your project.
Move the script buildAndTest.sh and MakeFile to the root folder of your project:
mv Scripts/buildAndTest.sh .
mv Scripts/Makefile .Add this sh "${PROJECT_DIR}/Scripts/RunTests.sh"
Before starting this portion, you will want to have your git repo pushed someplace jenkins can get to it. I hear github works?
Use the option Poll SCM with the settings * * * * *
sh "$WORKSPACE/buildAndTest.sh"The path to the JUnit XML files is here: build/test-results/*.xml
Okay, so we can run our unit tests. What next? In the true nature of CI, we keep integrating. We should build the actual app.
Change it from Poll SCM to Build after other projects are built. Provide the name of your UnitTesting Job.
Update the shell command to have this:
cd "$WORKSPACE"
xcodebuild -target MyTestApplication -configuration Debug -sdk iphonesimulator buildIn the Post-build Actions you will want to setup some notifications. E-mail is the easiest if your team is small.
At this point, Jenkins will build and run the GHUnitTest every time your push an update to your git repo. On success, it will test compiling the entire app as a Debug simulator build. It is possible build signed release versions, but it requires moving keychain and mobileprovisioning profiles around.
Try playing around with some Jenkins notification plugins to make the best use of the feedback it can provide.
I've pulled parts of this from all over the place. If you see you work in here, push an update to this section.











