はじめに
FBSnapshotTestCaseを拡張してUIImage, NSAttributedStringの検証を行う方法です。
extension FBSnapshotTestCase {
UIImageを検証するメソッド
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)
}
NSAttributedStringを検証するメソッド
func FBSnapshotVerifyAttributedString(_ string: NSAttributedString, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
let label = UILabel()
label.attributedText = string
label.numberOfLines = 0
label.sizeToFit()
FBSnapshotVerifyView(label, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line)
}
検証方法
FBSnapshotVerifyImage(UIImage(named:"hogehoge"))
let string = NSMutableAttributedString(string: "あいう")
....
FBSnapshotVerifyAttributedString(string)