FBSnapshotTestCaseでUIImageのテストを行う。


はじめに

FBSnapshotTestCaseはUIViewのレイアウトをテストするライブラリですが、以下のカテゴリーメソッドを追加する事によってUIImageのテストも行う事ができます!


extension FBSnapshotTestCase {

    func FBSnapshotVerifyImage(_ image: UIImage, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
        FBSnapshotVerifyView(UIImageView(image: image), identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
    }

}

実際の呼び出し例は以下の通りです。

   var image: UIImage!

  UIImageの生成処理

   ...(テストコード)

  FBSnapshotVerifyImage(image)