LoginSignup
7
3

More than 3 years have passed since last update.

fastlaneでXcode11の新機能Test Planを使う

Last updated at Posted at 2019-12-24

Test PlanはXcode11から使えるようになった機能で、
Xcode11より前だったらbuild schemeごとに指定していたArgumentsやOptions、Diagnosticsなどの設定が、.xctestplanという拡張子のファイルを使って設定できるようになっています。

Test PlanではTestファイルの中の1テスト(testから始まるfunction)ごとに実行するかどうかの細かな指定も可能になっています。

詳しい説明はDeNAさんのこちらの記事 https://swet.dena.com/entry/2019/10/23/080000 がわかりやすかったので、そちらを参考にしてみてください。

fastlaneでTest Planを実行する

fastlane scanのドキュメント https://docs.fastlane.tools/actions/scan/#scan にはまだTest Planに関するオプションがなかったので、xcodebuildコマンドを使って-testPlanオプションを指定して実行するようにしました。

具体的には他のlaneから呼び出せるようにFastfile内に定義して、以下のように実行しています。


lane :unit_test do |options|
  scheme = options[:env] != nil ? options[:env] : "dev"
  project = 'TestProject'
  destination = 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.1'
  testplan = ENV['CI'] ? "unit.ci" : "unit.local"

  run_test(scheme, project, destination, testplan)
end

def run_test(scheme, project, destination, testPlan)
  sh "set -o pipefail && xcodebuild test -scheme #{scheme} -project #{project} -destination '#{destination}' -testPlan '#{testPlan}' -derivedDataPath DerivedData -enableCodeCoverage YES ENABLE_TESTABILITY=YES | xcpretty"
end

unit_testというlaneを実行することで、unit test用のTest Planを使ったテストの実行ができるようになります。

2020/02/20追記 別の書き方

上記ではxcodebuildコマンドを使用しましたが、run_testsxcargsオプションでテストプランを指定できるそうです。
https://qiita.com/kotala_b/items/00f19ecaef6cae50e161#comment-3df02864954c4145e9fa

run_tests(
  scheme: "#{scheme}",
  xcargs: "-testPlan #{testPlan}"
)

既にrun_testsscanコマンドを使っている場合には、xcargsを追加した方が良さそうですね!

7
3
1

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
7
3