4

在经历了一些严重的挫折和头痛之后,我设法将单元测试添加到现有项目中。问题是,测试只执行了 50% 的时间。我有一个内部带有 STFail 宏的测试方法,当我运行测试时,它会按我的预期失败。然后,我在不触及任何代码/设置的情况下再次运行测试,它将通过而不会在测试夹具中遇到断点。发生这种情况时,控制台会打印出此输出:

无法找到位于 ... octest 的测试包的可执行文件。

我有一个谷歌,但似乎没有很多/任何人有这个确切的问题,关于这个主题的其他讨论让我头疼。如果有人能对这个问题有所了解,将不胜感激。

谢谢。

4

1 回答 1

3

I took your fresh project and reproduced the problem. There are a number of issues, and one unknown:

Build Phases of test target:

  • Target Dependencies: Specify TestApp, so that the main target is always built first.
  • Compile Sources: Don't include any main sources. Only include TestAppUnitTests.mm
  • Link Binary With Libraries: The only one needed is SenTestingKit.framework. We can throw in Foundation and UIKit for good measure.
  • Copy Bundle Resources: Should have nothing. (Later, you may want test-specific resources.)

Build Settings of test target:

  • Bundle Loader should be $(BUILT_PRODUCTS_DIR)/TestApp.app/TestApp
  • Test Host should be $(BUNDLE_LOADER)

Scheme of main target:

  • Test -> Info should specify the test target

But even if I make all these changes, your project still has the odd behavior. The simulator sometimes gets a version of the app named, literally, ${PRODUCT_NAME}. Even debugging the app sometimes shows "Debug ${EXECUTABLE_NAME}" in the Log Navigator. So something else is awry, and I don't know what.

The best solution is to create a new project from scratch, specifying "Include Unit Tests". I've verified that this works.

于 2012-09-27T15:26:52.040 回答