Unit Tests fail, then don't

前端 未结 1 1436
孤街浪徒
孤街浪徒 2021-01-06 05:49

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 t

相关标签:
1条回答
  • 2021-01-06 06:18

    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.

    0 讨论(0)
提交回复
热议问题