![見出し画像](https://assets.st-note.com/production/uploads/images/74579182/rectangle_large_type_2_17afb9b3a3e5dd6dc210cc2e677e7617.png?width=1200)
Xcode13.3のTesting周りについてまとめてみた
Xcode13.3がリリースされました。
この13.3にはTestingの箇所があったので次について少しまとめてみました。
テストの実行回数の表示
xctestproductバンドルフォーマットのサポート
テストの実行回数の表示
When running tests repeatedly, the test runner now prints the current iteration number to the console. (83848153)
Xcode13からテストの繰り返しがおこなえるようになりました。
それについては次の記事に軽くまとめています。
今まで
今までは繰り返し実行をしていても実行時のログには次のようなものが実行分表示されていました。
Test Case '-[Sample.SampleTests test_sample]' started.
Test Case '-[Sample.SampleTests test_sample]' passed (0.000 seconds).
Test Case '-[Sample.SampleTests test_sample]' started.
Test Case '-[Sample.SampleTests test_sample]' passed (0.000 seconds).
Xcode13.3から
Xcode13.3から次のように回数が表示されるようになりました。
Test Case '-[Sample.SampleTests test_sample]' started (Iteration 96 of 100).
Test Case '-[Sample.SampleTests test_sample]' passed (0.000 seconds).
Test Case '-[Sample.SampleTests test_sample]' started (Iteration 97 of 100).
Test Case '-[Sample.SampleTests test_sample]' passed (0.000 seconds).
便利になりましたね!
xctestproductバンドルフォーマットのサポート
xcodebuild now supports an .xctestproducts bundle format for the build-for-testing and test-without-building actions. Using a bundle makes it easier to run tests, particularly when transporting tests between systems. Use the new -testProductsPath argument to set the path to the bundle.
XCTestのUIテストには必要なものをビルドする「build-for-testing」と、それを利用してテストを実行する「test-without-building」というxcodebuildのコマンドがあります。
この機能自体はXcode8から導入されたものです。
これにより事前にビルドしておいて、それを利用して並列実行をするという方法ができるようになっています。
デバイスファームではこれを利用してテストを実行しています。
今まで
今までは、build-for-testingを実行すると.xctestrunが生成されました。
このファイルは「テストターゲットのアプリファイル」「テストランナーのアプリファイル」「テストバンドル」のパスがそれぞれ記載されているplist形式のファイルです。
そのためデバイスファームなどでテストを実行する場合、このxctestrunと実際に利用するファイル群が必要でした。
だいたいはすべてを1つのzipにまとめてアップするというものでした。
Xcode13.3から
今回からサポートされたxctestproductsバンドルは上述したxctestrunとそこ
に記載されているパスにあるものが内包されています。
このバンドルは次のコマンドから生成することができます。
$ xcodebuild build-for-testing -project MyProject.xcodeproj
-scheme App
-testProductsPath ./App.xctestproducts
そして、このバンドルだけあれば次のコマンドでテストを実行することができるようになります。
$ xcodebuild test-without-building
-testProductPath ./App.xctestproducts -destination [...]
今までより便利になりましたが、これがデバイスファームで利用できるようになるかはデバイスファームがサポートするか次第なので、気長に待ちましょう。
ただオンプレミスで実行環境を用意しているところでは、今からでも活用できると思います。