我有一些项目我正在尝试使用Xcode 6 Beta 2.这些项目都有一些类型的库使用XCTest(Kiwi/XCTest和Specta)而不是在Xcode 6中构建,因为XCTest/XCTest.h不能被发现.
fatal error: 'XCTest/XCTest.h' file not found
#import <XCTest/XCTest.h>
Run Code Online (Sandbox Code Playgroud)
我注意到XCTest.framework不再出现在"带有二进制文件的链接库"构建阶段列表中,但这很好,因为当我使用Xcode 6 创建一个新项目时,看起来库是自动链接的.
也许是一些相关性,我的XCTest需要的依赖关系都是通过Cocoapods引入的.
有什么我不知道我需要用我的项目更新吗?
在一个新项目中,我有这个简单的测试
#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
Run Code Online (Sandbox Code Playgroud)
ViewController.h 不是测试目标的一部分,但它编译并运行测试没有任何问题.

我认为这是因为应用程序首先构建(作为依赖)然后是测试.链接器然后找出ViewController类是什么.
但是,在较旧的项目中,使用完全相同的测试和ViewController文件,构建在链接器阶段失败:
Run Code Online (Sandbox Code Playgroud)Undefined symbols for architecture i386: "_OBJC_CLASS_$_ViewController", referenced from: objc-class-ref in ViewControllerTests.o
即使创建了新的XCTest单元测试目标,也会发生此链接器错误.
为了解决这个问题,可以在应用程序和测试目标中包含源(勾选上图中的两个框).这会在模拟器的系统日志中导致重复符号的构建警告(打开模拟器并按cmd- /查看):
Run Code Online (Sandbox Code Playgroud)Class ViewController is implemented in both [...]/iPhone Simulator/ [...] /MyApp.app/MyApp and [...]/Debug-iphonesimulator/LogicTests.octest/LogicTests. One of the two will be used. Which one is undefined.
这些警告偶尔会导致以下示例说明的问题: …