LoginSignup
38
39

More than 5 years have passed since last update.

CocoaPods環境下でJenkinsを利用する

Posted at

CocoaPodsを利用しているプロジェクトでJenkinsを使ったテストを行いたかったのでメモ
前提としてXcodeのバージョンは4.5.2を使用、テストフレームワークはSenTestingKitを利用する場合になります。(Kiwi等含む)

1.テスト用のスキーマの追加

xcodebuildはworkspaceが対象の場合、targetオプションを同時に指定できないためスキーマを指定する必要がある

  • Product -> New Schemeからテスト用のターゲットを指定してスキーマを追加
    スクリーンショット

  • Product -> Edit Schemeから追加したスキーマを実行できるように変更
    スクリーンショット

  • Product -> Manage SchemesからSharedオプションをオンにする。(スキーマ設定をxcuserdataからxcshareddataへ移動)
    スキーマをgit管理に加える
    git add SampleProduct.xcodeproj/xcshareddata/xcschemes/SampleProductTests.xcscheme

2.Jenkinsのジョブの設定

以下のプラグインを予めインストールしておく

  • CocoaPods Jenkins Integration
  • Jenkins GIT plugin
  • XCode integration

Xcodeのビルド設定は以下のように指定
スクリーンショット


ここまででJenkinsのビルド実行を行うとビルドが出来るようになっているはずです。
ただテストはスキップされてしまっているので続けて以下の設定を行います。

Jenkinsでの初回ビルドはworkspace内のschemeを認識できないので必ず失敗します。
そのため一度は手動でSampleProduct.xcworkspaceを立ち上げる必要があります。(一度開いたらもう閉じても問題ありません。)

3.テストを実行するためのセットアップ

  • ios-simのインストール
brew install ios-sim

でインストール可能

次に、XcodeプロジェクトのテストターゲットのBuild PhasesRun Scriptを以下の通り変更

 # Run the unit tests in this test bundle.
-"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
+"${PROJECT_DIR}/Scripts/run_tests.sh"

run_tests.shをダウンロードし、${PROJECT_DIR}/Scripts/に保存

Kiwiを利用している場合は、run_test.shを以下の通り変更

 # Test the log output for test case failure. If this line is present, exit 1
-if egrep "Test Case '-\[[[:alnum:]]+[[:space:]][[:alnum:]]+\]' failed" ${test_logfile}
+if egrep "\[FAILED\]" ${test_logfile}

これで再度ビルド実行を行うとテストまで含めて実行されると思います。

参考

http://axeman.in/blog/2012/12/02/setting-up-jenkins-ci-for-ios-development/
https://github.com/urbanairship/ios-library/blob/master/run_sim_app_tests.sh

38
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
39