Xcode unittest build failed with error "Undefined symbols for architecture x86_64"

According to this link, I need to set Bundle Loader with below content in unittest target Build Settings

$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp


At least as of Xcode 7.3 test targets let you select a "Host Application". In the Test target (but not presently the UI Test target) this automatically populates the "Test Host" build setting, but not the "Bundle Loader", which can lead to classes not being found.

Considering this, if you set your test targets' "Bundle Loader" Build Setting to $(TEST_HOST), it will always contain the right value even if you change the Host Application.

This is effectively the opposite of the advice given in the link @yuwen-yan posted, and should amount to less work.


This error may be the result of having wrong test target type, namely ui test target.

UI test targets can't use the internals of the main target, not even with @testable imports. Unit test targets OTOH can use the internals.

See more details in this answer.

(I believe this has changed in some XCode version which causes confusion. Typical way is just to include a huge bunch of files from the original target in the ui test target. A proper way is to design UI tests in such a way that they don't need or use much code from the main target.)

Tags:

Ios

Xcode