Xcode中。添加到测试目标的图像资源不会复制到测试包中

时间:2018-04-12 10:31:52

标签: swift xcode unit-testing

我写了一些UIImage课程的扩展名,并希望通过单元测试来覆盖它。我添加了一些图像来测试目标并检查它是否出现在Copy Bundle Resources列表中。 Copy Bundle Resources

在测试代码中,我使用了一个模型对象,它可以提供测试数据。

class TestConstants {
    private static var bundle: Bundle {
        return Bundle(for: UIImageExtensionsTests.self)
    }
    private static var birdImageURL: URL {
        let path = self.bundle.url(forResource: "birds", withExtension: "png")
        return path!
    }
    static var birdImageData: Data {
        return try! Data(contentsOf: self.birdImageURL)
    }
}

不幸的是birds.png图片不在测试包中,而是另一个资源drm.txtenter image description here enter image description here 我有点困惑是Xcode中的错误吗? 顺便说一句,我下载了Xcode 9.4 beta并且存在相同的行为 - 图像不会复制到测试包中。

enter image description here

#UPDATE

UIImageExtensionsTests是使用drm.txtbirds.png文件在同一目标中显示的测试类

enter image description here enter image description here

2 个答案:

答案 0 :(得分:0)

要使用相应的Bundle:

 let bundle = Bundle.init(for: TestConstants.classForCoder())

答案 1 :(得分:0)

我很遗憾我没有仔细阅读日志。 这个问题发生在互联网上建立的“错误”形象。 Xcode无法继续处理图像,因此它没有将其复制到测试包中。

  

阅读时   /Users/igork/developer/gitlab/ios.gym-master/GymMasterTests/Resources/birds.png   pngcrush抓住了libpng错误:不是PNG文件..

enter image description here

此错误不会导致构建和运行目标。所以在我的情况下,测试开始了:(

相关问题