Quartz Core干扰运行单元测试

时间:2012-12-03 16:16:03

标签: ios xcode unit-testing quartz-graphics

我正在尝试在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的文件,我遇到了同样的问题。

其他人是否遇到此问题或有任何有用的建议?

由于

2 个答案:

答案 0 :(得分:1)

对于单元测试,您只想测试应用程序的逻辑,并尝试省略与UI或应用程序核心逻辑不必要的任何额外类/框架有关的任何内容。要做到这一点,您可能必须将一些逻辑移动到另一个文件,该文件只是所需的最小代码。基本上,不要在单元测试中导入石英芯/使用石英芯。将您正在测试的逻辑移动到另一个测试类中。

答案 1 :(得分:0)

将缺少的框架添加到测试包中。

enter image description here

正如Kris所说 - 这可能是一个坏主意,但在某些情况下,您实际上需要核心图形进行单元测试。

相关问题