1

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

还有其他人经历过这个或有任何有用的建议吗?

谢谢

4

2 回答 2

1

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

于 2012-12-03T16:26:00.680 回答
0

Add the missing framework to your test bundle.

enter image description here

As Kris mentioned - this may be a bad idea, but there are situations where you would actually want a core graphics for your unit tests.

于 2013-12-27T12:07:36.103 回答