Unit Tests fail, then don't

╄→гoц情女王★ 提交于 2019-11-30 18:18:53

问题


After some serious frustration and headaches, I've managed to add unit tests to an existing project. The problem is, the tests only get executed 50% of the time. I have a test method with an STFail macro inside, when I run the tests, it fails as I'd expect. Then, I run the tests again without touching any code/settings and it will pass without hitting breakpoints in the test fixture. The console prints out this output when this happens:

The executable for the test bundle at ... octest could not be found.

I've had a Google but there doesn't seem to be many/any people with this exact issue and other discussions on the subject are going over my head. If anyone can shed some light on this issue, It'll be very much appreciated.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/12546238/unit-tests-fail-then-dont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!