LoginSignup
6
9

More than 5 years have passed since last update.

Quickをfastlaneから実行してテストする

Last updated at Posted at 2016-11-10

Quick

QuickというSwift, Objective-C用のテスティングフレームワークを使ったテストをfastlaneで流してみる。

とりあえずSingle View Application で QuickSample というプロジェクトを作成する。

スクリーンショット 2016-10-31 18.33.35.png

スクリーンショット 2016-10-31 18.55.17.png

プロジェクト配下に移動して、以下の内容でPodfileを作成する。
一応Swiftのバージョンを指定している。

Podfile
 Podfile

use_frameworks!
swift_version = '3.0'

def testing_pods
    pod 'Quick'
    pod 'Nimble'
end

target 'QuickSampleTests' do
    testing_pods
end

target 'QuickSampleUITests' do
    testing_pods
end

Cocoapodsで依存ライブラリをインストールする。

$ pod install
[!] The `QuickSampleTests [Debug]` target overrides the 
`ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target
 Support Files/Pods-QuickSampleTests/Pods-QuickSampleTests.debug.xcconfig'. This
 can lead to problems with the CocoaPods installation

とか出ても一旦放っておく。
直す場合は、ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIESで検索かけて、設定を$(inherited)にすれば良い。

include Unit Testsでプロジェクトを作ったので、XCTest版のテストクラスが用意されている。
今回はそれをリネームしてQuickで書いていくことにする。

QuickSampleTests.swift → `QuickSampleSpec.swift

とりあえずこんな感じで雑に書いて動かしてみる。

import Quick
import Nimble
@testable import QuickSample

class QuickSampleSpec: QuickSpec {
    override func spec() {
        describe("ほげほげの場合") {
            it("こうなる") {
                expect("A").to(equal("A"))
            }
        }
    }

}

とりあえずXcode上では動いた:thumbsup:

スクリーンショット 2016-11-02 20.07.06.png

fastlaneで実行

fastlane

インストール

$ gem install fastlane

初期化

$ fastlane init

以下のようなエラーが出た:fearful:

No teams available on the Developer Portal
You must accept an invitation to a team for it to be available
To learn more about teams and how to use them visit https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/ManagingYourTeam/ManagingYourTeam.html
[07:48:42]: Your account is in no teams
[07:48:42]: An error occured during the setup process. Falling back to manual setup!

どうやらDeveloper Programに登録しないとダメっぽい?:thinking: (必要ないよ!って場合はコメントください!!)

ので、Appleにお布施して:dollar:

再度initしてやると成功した。

$ fastlane init

1__tenten0213_tentenMBA____QuickSample__zsh_.png

初期化した状態でとりあえずテストできそうだったからテストしてみる。

$ fastlane test

シミュレータ立ち上がったりして、結構時間がかかる。

ちゃんと、書いたテストが動作した!:relaxed:

1__tenten0213_tentenMBA____QuickSample__zsh_.png

htmlとjunit形式のレポートが出るみたい。
Jenkinsとかでも扱いやすくて良い。

<?xml version='1.0' encoding='UTF-8'?>
<testsuites name='QuickSampleTests.xctest' tests='2' failures='0'>
  <testsuite name='QuickSampleUITests.QuickSampleUITests' tests='1' failures='0'>
    <testcase classname='QuickSampleUITests.QuickSampleUITests' name='testExample' time='6.398'/>
  </testsuite>
  <testsuite name='QuickSampleTests.QuickSampleSpec' tests='1' failures='0'>
    <testcase classname='QuickSampleTests.QuickSampleSpec' name='ほげほげの場合__こうなる' time='0.006'/>
  </testsuite>
</testsuites>

HTMLの方は若干ダサいけど、まぁよし。

Test_Results___xcpretty.png

Quickやfastlaneの詳細な使い方は今後しらべないと:muscle:

6
9
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
6
9