LoginSignup
0
1

More than 3 years have passed since last update.

UIImage, NSAttributedStringのテスト方法

Last updated at Posted at 2019-05-19

はじめに

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)
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