FBSnapshotTestCase 不创建 FB_REFERENCE_IMAGE_DIR 和 IMAGE_DIFF_DIR 文件夹
FBSnapshotTestCase does not create the FB_REFERENCE_IMAGE_DIR and IMAGE_DIFF_DIR folders
这是我的测试:
class ZabiTests:FBSnapshotTestCase {
var vc:UIViewController?
override func setUpWithError() throws {
super.setUp()
vc = ViewController()
recordMode = true
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
FBSnapshotVerifyView((vc?.view)!)
}
func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
我第一次 运行 使用 recordMode = true 然后我 运行 没有这条线,我仍然得到快照比较失败
(vc 没问题,红色背景而不是 nil )
在试用它之后,我通过创建自己的基础创建了一种自动定义这些文件夹的替代方法 class:
open class MySnapshotTestCase: FBSnapshotTestCase {
var referenceImageDirectory: String?
var imageDiffDirectory: String?
public func verify(
view: UIView,
file: StaticString = #file,
line: UInt = #line
) {
let directory = ("\(file)" as NSString).deletingLastPathComponent
// Save for later use in getReferenceImageDirectory
referenceImageDirectory = NSString.path(withComponents: [directory, "ReferenceImages"])
// Save for later use in getImageDiffDirectory
imageDiffDirectory = NSString.path(withComponents: [directory, "FailedSnapshotTests"])
FBSnapshotVerifyView(
view,
identifier: nil,
perPixelTolerance: 0,
overallTolerance: 0,
file: file,
line: line)
}
open override func getReferenceImageDirectory(withDefault dir: String?) -> String {
guard let referenceImageDirectory = referenceImageDirectory else {
fatalError("Do not call FBSnapshotVerifyView directly, use WazeSnapshotTestCase.verify instead.")
}
return referenceImageDirectory
}
open override func getImageDiffDirectory(withDefault dir: Swift.String?) -> Swift.String {
guard let imageDiffDirectory = imageDiffDirectory else {
fatalError("Do not call FBSnapshotVerifyView directly, use WazeSnapshotTestCase.verify instead.")
}
return imageDiffDirectory
}
}
这是我的测试:
class ZabiTests:FBSnapshotTestCase {
var vc:UIViewController?
override func setUpWithError() throws {
super.setUp()
vc = ViewController()
recordMode = true
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
FBSnapshotVerifyView((vc?.view)!)
}
func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
我第一次 运行 使用 recordMode = true 然后我 运行 没有这条线,我仍然得到快照比较失败
(vc 没问题,红色背景而不是 nil )
在试用它之后,我通过创建自己的基础创建了一种自动定义这些文件夹的替代方法 class:
open class MySnapshotTestCase: FBSnapshotTestCase {
var referenceImageDirectory: String?
var imageDiffDirectory: String?
public func verify(
view: UIView,
file: StaticString = #file,
line: UInt = #line
) {
let directory = ("\(file)" as NSString).deletingLastPathComponent
// Save for later use in getReferenceImageDirectory
referenceImageDirectory = NSString.path(withComponents: [directory, "ReferenceImages"])
// Save for later use in getImageDiffDirectory
imageDiffDirectory = NSString.path(withComponents: [directory, "FailedSnapshotTests"])
FBSnapshotVerifyView(
view,
identifier: nil,
perPixelTolerance: 0,
overallTolerance: 0,
file: file,
line: line)
}
open override func getReferenceImageDirectory(withDefault dir: String?) -> String {
guard let referenceImageDirectory = referenceImageDirectory else {
fatalError("Do not call FBSnapshotVerifyView directly, use WazeSnapshotTestCase.verify instead.")
}
return referenceImageDirectory
}
open override func getImageDiffDirectory(withDefault dir: Swift.String?) -> Swift.String {
guard let imageDiffDirectory = imageDiffDirectory else {
fatalError("Do not call FBSnapshotVerifyView directly, use WazeSnapshotTestCase.verify instead.")
}
return imageDiffDirectory
}
}