【发布时间】:2015-11-27 17:23:42
【问题描述】:
我的单元测试目标在 Xcode 7 上崩溃。
我使用指定的应用委托类对我的项目执行单元测试,这与我的常规应用委托不同。 UnitTestAppDelegate 不是应用目标的成员,只是测试目标的成员。
在 Xcode 6 中它工作正常,使用了正确的委托,但在 Xcode 7(beta 6)中,应用程序在尝试加载测试委托时崩溃。我使用模拟器进行测试,iOS 8 和 9。
应用目标不知道该文件:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to instantiate the UIApplication delegate instance. No class named UnitTestAppDelegate is loaded.'
我的main.m 文件如下所示:
int main(int argc, char* argv[])
{
int returnValue;
@autoreleasepool
{
if (NSClassFromString(@"XCTest") != nil)
{
//use the test delegate
returnValue = UIApplicationMain(argc, argv, nil, @"UnitTestAppDelegate");
}
else
{
//use the normal delegate
returnValue = UIApplicationMain(argc, argv, nil, @"AppDelegate");
}
}
return returnValue;
}
我还附上了我的方案如何配置的屏幕截图(运行和测试在同一个方案中,尽管我也尝试将它们分开)。
将我的UnitTestAppDelegate 添加为应用程序目标的成员可以修复崩溃,但我显然不想将文件添加到我的应用程序中。
其他人遇到过这个吗?
有什么想法吗?
【问题讨论】:
-
我创建了一个小型演示项目,如果有人想尝试解决它。 github.com/ashavit/UnitTests-Different-AppDelegate
标签: ios unit-testing ios8 appdelegate xcode7-beta6