LoginSignup
2
0

More than 5 years have passed since last update.

fastlaneでXCTestを実行してコードカバレッジレポートを取得する【iOSアプリ】

Last updated at Posted at 2018-08-14

fastlane でXCTestを実行した時に、slatherを使ってこんな風なコードカバレッジのレポートを取得する方法です。

サマリー

サマリー

詳細一部(上記サマリーでFileを選択してクリック)

詳細

設定方法

前提

  • XCTest用のテストコードは作成済み
  • fastlaneはインストール済み

"Gather coverage data"を有効にする

Xcodeで、Edit scheme... > Test > Gather coverage data にチェックを入れて有効にする

slatherのインストール

fastlaneをインストールしただけだと、slatherはインストールされないのでインストールします。ターミナルで下記コマンドを実行。

gem install slather

Fastfileにslatherのアクションを追加する

最低限の定義例は次の通りです。scheme, projは対象のプロジェクトに合わせて変更してください。

default_platform(:ios)

platform :ios do

  desc "run test"
  lane :tests do
    run_tests(
      scheme: "samplebot",
      code_coverage: true,
      clean: true
    )
    slather(
      proj: "samplebot.xcodeproj",
      scheme: "samplebot",
      html: true
    )
  end

end

XCTestを実行するrun_testsアクションで、コードカバレッジを生成するためにcode_coverageをtrueに設定。slatherアクションで、カバレッジレポートをHTMLに出力するために、htmlをtrueに設定

テストを実行

Fastfileの定義した、testsを実行します。プロジェクトフォルダでターミナルから下記コマンドを実行。

fastlane tests

実行後

正しく実行できれば、レポート結果がhtmlフォルダに出力されます。index.htmlがサマリーです。

参考

この辺りを参考に。

slatherを試してサマリーしか見られないかと思いきや、htmlをtrueにするだけでレポートができました。

2
0
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
2
0