【发布时间】:2023-03-05 02:05:01
【问题描述】:
我正在尝试为我的 iPhone 应用程序设置单元测试。我遵循Apple Unit Testing documentation 并唤醒了它,但是一旦我在该测试中添加了另一个类,我就会收到以下错误:
"_OBJC_CLASS_$_RootViewController", referenced from:
__objc_classrefs__DATA@0 in AppDelegateTests.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
应用程序本身是一个基本的导航应用程序,带有用于数据存储的核心数据。
单元测试如下:
#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "HSStabilityAppAppDelegate.h"
#import "RootViewController.h"
@interface AppDelegateTests : SenTestCase {
HSStabilityAppAppDelegate *appDelegate;
}
@end
@implementation AppDelegateTests
// all code under test must be linked into the Unit Test bundle
#pragma mark -
#pragma mark Set up and tearDown
#if APPLICATION_TESTS
- (void) setUp {
appDelegate = (HSStabilityAppAppDelegate *)[[UIApplication sharedApplication] delegate];
STAssertNotNil(appDelegate, @"Cannot find the application delegate.");
}
- (void) tearDown {
[appDelegate release];
}
#else
#endif
#pragma mark -
#pragma mark Tests
#if APPLICATION_TESTS
- (void) testRootViewIsOnTop {
id topViewControllerClass = [[appDelegate.navigationController topViewController] class];
id rootViewControllerClass = [RootViewController class];
STAssertEquals(topViewControllerClass, rootViewControllerClass, @"Root view controller was not the top class");
}
#endif
@end
如果我注释掉 id rootViewControllerClass 行,则程序链接正确。 此外,这只发生在针对设备目标构建时,如果针对模拟器构建我没有任何问题(可能是因为应用程序测试在模拟器上不起作用)。
任何人都可以帮助解决这个基本且非常令人恼火的问题吗?
【问题讨论】:
标签: iphone unit-testing symbols