LoginSignup
0
1

More than 5 years have passed since last update.

FBSnapshotTestCaseとKIFを共存させて、UI操作→画面の表示のユニットテストを実現する。

Last updated at Posted at 2018-11-30

はじめに

UIのユニットテスト(≠UIテスト)でテストコードを書く場合、以下のフローで書きたいでしょう。

UI操作→表示された画面の検証

で調べてた所、単体でうまくやってくれるやり方、ライブラリがわかりませんでした。

この問題はKIFとFBSnapshotTestCaseを共存させる事によって解決することができます。

実際のコード例

以下の関数を定義します(出典:https://blog.karumi.com/ui-testing-for-ios/)。


func tester(file: String = #file, _ line: Int = #line) -> KIFUITestActor {
    return KIFUITestActor(inFile: file, atLine: line, delegate: nil)
}

FBSnapshotTestCaseのサブクラスで以下のように呼び出すことができます。


   // UI操作
   tester().tapView(withAccessibilityIdentifier:"閉じるボタン")

   ...

   // 画面の検証
   FBSnapshotVerifyView(view)

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