Xcode.添加到测试目标的图像资源不会复制到测试包中 [英] Xcode. Image resources added to a test target are not copied into the tests bundle
问题描述
我为 UIImage
类编写了一些扩展,并希望通过单元测试覆盖它.我添加了一些图像来测试目标并检查它是否出现在 Copy Bundle Resources
列表中.
I wrote some extension to UIImage
class and want to cover it by Unit Tests. I added some image to test target and checked that it presents in the Copy Bundle Resources
list.
在测试代码中,我使用了一个模型对象,它为我提供了测试数据.
In the test code I use a model object which pvovides me test data.
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.txt
.我有点困惑,这是 Xcode 中的错误吗?顺便说一下,我下载了 Xcode 9.4 beta 并且有相同的行为 - 图像不会复制到测试包中.
Unfortunately birds.png
image is not located in test bundle, but another resource drm.txt
presents.
I'm a bit confused is it the bug in Xcode?
By the way I downloaded Xcode 9.4 beta and there are the same behavior - images do not copy into the test bundle.
#UPDATE:
UIImageExtensionsTests
是与 drm.txt
和 birds.png
文件在同一目标中的测试类
UIImageExtensionsTests
is a test class presents in the same target with drm.txt
and birds.png
file
推荐答案
我的错是我没有仔细阅读日志.这个问题发生在互联网上的错误"形象.Xcode 无法处理图像,因此它没有将其复制到测试包中.
My bad that I didn't read log carefully. The issue was happen with "wrong" image founded in internet. Xcode couldn't proceed image, so it didn't copy it to test bundle.
阅读时/Users/igork/developer/gitlab/ios.gym-master/GymMasterTests/Resources/birds.pngpngcrush 捕获 libpng 错误:不是 PNG 文件..
While reading /Users/igork/developer/gitlab/ios.gym-master/GymMasterTests/Resources/birds.png pngcrush caught libpng error: Not a PNG file..
并且此错误不会导致构建和运行目标失败.所以在我的情况下,测试开始了:(
And this error doesn't fail building and running the target. So in my case the tests were starting :(
这篇关于Xcode.添加到测试目标的图像资源不会复制到测试包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!