我正在尝试在 Xcode 4.4 中尝试新的单元测试(无论如何对我来说都是新的,因为我之前使用过 OHUnit)。
我有几个要添加到目标的类,但其中一个引用了 QuartzCore。
显然我已经将我的单元测试目标链接到 QuartzCore 框架,但它无法运行:
Undefined symbols for architecture armv7s:
"_CGBitmapContextCreateImage", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGContextDrawImage", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGBitmapContextCreate", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGImageGetBitsPerComponent", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGImageRelease", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGContextSetShadowWithColor", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGContextRelease", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGRectZero", referenced from:
-[UIImage(Additions) imageByScalingProportionallyToSize:] in UIImage+Additions.o
"_CGColorSpaceRelease", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
"_CGColorSpaceCreateDeviceRGB", referenced from:
-[UIImage(Additions) imageWithShadow] in UIImage+Additions.o
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的构建目标构建成功,但单元测试目标构建失败。
我尝试创建一个空白的新项目,并添加一个使用 QuartzCore 的文件,但我遇到了同样的问题。
有其他人遇到过这种情况或有任何有用的建议吗?
谢谢
最佳答案
对于单元测试,您只想测试应用程序的逻辑,并尝试忽略与 UI 相关的任何内容或应用程序核心逻辑不需要的任何额外类/框架。为此,您可能必须将一些逻辑移动到另一个文件,这只是所需的最少代码。基本上,不要在单元测试中导入 quartz 芯/使用 quartz 芯。将您正在测试的逻辑移到另一个测试类中。
关于ios - Quartz Core 干扰正在运行的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687322/