どうも、ささおです!
今回はBitriseでCIを試せる入門記事を書いていきます。
超簡単なので10分あれば試せます!
ぜひやってみてください!
Contents
必要なもの
- Githubアカウント
- Bitriseアカウント
- Xcode
Bitriseとは
iOSアプリ開発で多く使われるCIサービスです。
CI(継続的インテグレーション)とはビルドやテストを継続的に実行することでエラーを素早く修正することができる開発手法です。
Tutorial
Githubでリポジトリの作成
まずはGithubでリポジトリを作成しましょう。

リポジトリ名は『BitriseTutorial』にします。わかればなんでもいいです。

Xcodeでプロジェクトの作成
“Create a new Xcode project”を選択してください。

“Single View App”を選択してください。

プロジェクト名はわかりやすいようにGithubのリポジトリと同じ“BitriseTutorial”にします。

プロジェクトをGithubにpush
ターミナルでこの手順通りにコマンドを実行してください。
$ git init $ git remote add origin https://github.com/ユーザー名/BitriseTutorial.git $ git push -u origin master
実行が完了したら、Githubで確認しましょう!
Bitriseでアプリの登録
Bitriseのページに行ったら、“Add New App”をクリックしてください。

アプリはprivateに設定します。

GithubでCIを回したいアプリを選択します。今回は先ほど作成した“BitriseTutorial”を選択します。

Githubのリポジトリへのアクセスは“No, auto-add SSH key”を選択します。Cocoapodsなどを利用している場合はちょっと違うようです。https://qiita.com/ktanaka117/items/1241afe53e2246444353#手順1-ビルド対象のプロジェクトに紐づいているbitriseのssh-keyの登録を解除する

ベースブランチの指定は“master”にしましょう。

エラーがおきますが、“Proceed anyway”を選択してください。

select ipa export methodは”development“を選択します。

BitriseでのXcodeのバージョンとローカルのXcodeのバージョンを揃えるためにbuild configurationを編集します。


Webhookの登録も済ませます。WebhookによってGithubにpushしたら自動でテストを回してくれます。

試しにpushしてみる
本当に自動テストされるのか確認してみます。
まずはテストを書いてみましょう。
Xcodeを開いてください。
ViewController.swiftを編集します。
ほんとは別のファイルに書いた方がいいのでしょうが、面倒だったのでViewControllerクラスの外にテストしたい関数を定義しました。
引数に入れた文字列をそのまま返す関数getです。
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } } func get(text: String) -> String { return text }
BitriseTutorialTests.swiftを編集します。
testExampleの中にXCTAssertEqual(“test”, get(text: “test”))を追加しました。
このように使うことができます。
XCTAssertEqual(予想される値, 実際の値)
“予想される値“と“実際の値”が一緒だとテスト成功です。
import XCTest @testable import BitriseTutorial class BitriseTutorialTests: XCTestCase { override func setUp() { // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. } func testExample() { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. XCTAssertEqual("test", get(text: "test")) } func testPerformanceExample() { // This is an example of a performance test case. self.measure { // Put the code you want to measure the time of here. } } }
実行してテストが成功するのか確認しましょう!
成功が確認できたら、
githubにpushしてみましょう。
$ git checkout -b "test" $ git add . $ git commit -m "test commit" $ git push -u origin test
そしてプルリクエストを作成しましょう。


作成が完了したらページの下部をみてみましょう。
“Some checks haven’t completed yet”となっているのでまだテストは完了していないようです。

完了するとこのようになります。

これでBitrise超入門終了です!
まとめ
どうでしたか??
細かくみたらよくわからないところも多かったのですが、とりあえずの導入は簡単にできましたね。
CIを手軽に試せたのは面白かったです。