什么时候需要将应用程序源包含在测试目标中?
在一个新项目中,我有这个简单的测试 #import <XCTest/XCTest.h> #import "ViewController.h" @interface ViewControllerTests : XCTestCase @end @implementation ViewControllerTests - (void)testExample { // Using a class that is not in the test target. ViewController * viewController = [[ViewController alloc] init]; XCTAssertNotNil(viewController, @""); } @end ViewController.h不是测试目标的一部分,但是它可以编译并运行测试而不会出现任何问题。 我认为这是因为应用程序首先(作为依赖项)构建,然后是测试。链接器然后找出ViewController类是什么。 但是,在具有完全相同的测试和ViewController文件的旧项目中,构建在链接器阶段失败: Undefined symbols for architecture i386: "_OBJC_CLASS_$_ViewController", referenced from: objc-class-ref in …