Xcode 9.4 fails to link test target without host application

Originator:pzabelin
Number:rdar://41067402 Date Originated:June 12, 2018
Status:Closed Resolved:2018-06-14
Product:Xcode Product Version:9.4
Classification:Serious Bug Reproducible:Always
 
Summary:

Previously we were able to create LOGIC tests in Xcode as opposed to APPLICATION tests. Xcode 9.4 fails to link logic tests with this message:

Undefined symbols for architecture x86_64:
  "type metadata accessor for <ClassUnderTest>", referenced from:
      <TestTarget.TestClass>.setUp() -> () in <TestTarget>.o
      type metadata accessor for <ClassUnderTest>.Type in <TestTarget>.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Steps to Reproduce:

Open attached project in Xcode 
Test GoodAppTestsWithoutHost scheme


Expected Results:

Tests link and pass

Actual Results:
Tests fails to link with error

Undefined symbols for architecture x86_64:
  "type metadata accessor for GoodApp.FirstViewController", referenced from:
      GoodAppTestsWithoutHost.GoodAppTestsWithoutHost.setUp() -> () in GoodAppTestsWithoutHost.o
      type metadata accessor for GoodApp.FirstViewController.Type in GoodAppTestsWithoutHost.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Version/Build:
Xcode Version 9.4 (9F1027a)

Configuration:
Debug

See attached project: https://github.com/paulz/TestableApp

Comments

Apple Developer Relations response

This looks like the expected behavior. It is not possible to have your tests reference symbols from an app target unless you use that app as the test host. If you wish to not use a host application, then you should put the code to be tested into a separate library or framework target which both your app and your tests can link against.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!