Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

はじめに

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)

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away