XCode7 UITesting - 如何添加主要目标 类 以便从 UITestCase 获得(未定义符号错误)?
XCode7 UITesting - how to add main target classes to be available from UITestCase (Undefined symbols error)?
我正在使用 XCode7 进行 UI 测试,需要一种方法将我的应用程序重置为某个初始状态。我有一个方法可以在我的一个 .m 文件中执行此操作,该文件是主要目标的一部分。
如何使主要目标的 类 在 UITestCase 中可用?
我尝试了常规导入,但出现链接器错误:
#import <XCTest/XCTest.h>
#import "CertificateManager.h"
@interface UITests : XCTestCase
@end
-(void)testWelcomeScreen
{
//put the app into initial state
[[CertificateManager sharedInstance] resetApplication];
//... proceed with test
}
错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CertificateManager", referenced from:
objc-class-ref in UITests.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已经将它与单元测试目标进行了比较,但是除了单元测试目标已经 "Allow testing host application APIs" 检查之外看不到差异,而 UI 测试目标根本没有这个选项。
UI 在与生产应用程序不同的进程中测试 运行。这意味着您无法从您的测试套件访问任何产品 类。
除了触摸屏幕之外,测试的唯一交互方式 UI 是设置启动参数或修改启动环境。
您可以使用其中任何一种在您的应用程序启动时对其进行重置。例如,在您的 UI 测试测试中:
@interface UITests : XCTestCase
@property (nonatomic) XCUIApplication *app;
@end
@implementation FooUITests
- (void)setUp {
[super setUp];
self.app = [[XCUIApplication alloc] init];
self.app.launchArguments = @[ @"UI-TESTING" ];
[self.app launch];
}
- (void)testExample {
// ... //
}
@end
然后,当您的应用启动时,您可以检查此参数。如果存在,请调用您应用的 "reset" 方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"UI-TESTING"]) {
[[CertificateManager sharedInstance] resetApplication];
}
return YES;
}
我正在使用 XCode7 进行 UI 测试,需要一种方法将我的应用程序重置为某个初始状态。我有一个方法可以在我的一个 .m 文件中执行此操作,该文件是主要目标的一部分。
如何使主要目标的 类 在 UITestCase 中可用?
我尝试了常规导入,但出现链接器错误:
#import <XCTest/XCTest.h>
#import "CertificateManager.h"
@interface UITests : XCTestCase
@end
-(void)testWelcomeScreen
{
//put the app into initial state
[[CertificateManager sharedInstance] resetApplication];
//... proceed with test
}
错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CertificateManager", referenced from:
objc-class-ref in UITests.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已经将它与单元测试目标进行了比较,但是除了单元测试目标已经 "Allow testing host application APIs" 检查之外看不到差异,而 UI 测试目标根本没有这个选项。
UI 在与生产应用程序不同的进程中测试 运行。这意味着您无法从您的测试套件访问任何产品 类。
除了触摸屏幕之外,测试的唯一交互方式 UI 是设置启动参数或修改启动环境。
您可以使用其中任何一种在您的应用程序启动时对其进行重置。例如,在您的 UI 测试测试中:
@interface UITests : XCTestCase
@property (nonatomic) XCUIApplication *app;
@end
@implementation FooUITests
- (void)setUp {
[super setUp];
self.app = [[XCUIApplication alloc] init];
self.app.launchArguments = @[ @"UI-TESTING" ];
[self.app launch];
}
- (void)testExample {
// ... //
}
@end
然后,当您的应用启动时,您可以检查此参数。如果存在,请调用您应用的 "reset" 方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"UI-TESTING"]) {
[[CertificateManager sharedInstance] resetApplication];
}
return YES;
}