XCode7 UITesting - 如何添加可从 UITestCase 使用的主要目标类(未定义符号错误)? [英] XCode7 UITesting - how to add main target classes to be available from UITestCase (Undefined symbols error)?

查看:20
本文介绍了XCode7 UITesting - 如何添加可从 UITestCase 使用的主要目标类(未定义符号错误)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XCode7 进行 UI 测试,需要一种方法将我的应用重置为某个初始状态.我有一种方法可以在作为主要目标的一部分的 .m 文件之一中执行此操作.

I'm doing UI testing with XCode7 and need a way to reset my app to some initial state. I have a method to do so in one of my .m files that are part of the main target.

如何使 UITestCase 中的主目标中的类可用?

我尝试了常规导入,但出现链接器错误:

I tried regular import, but get a linker error:

#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)

我已将其与单元测试目标进行了比较,但除了单元测试目标已选中允许测试主机应用程序 API"之外,看不出有什么不同,而 UITest 目标根本没有此选项.

I have compared this to the Unit test target, but cant see differences beyond that the unit test target has "Allow testing host application APIs" checked, while UITest target does not have this option at all.

推荐答案

UI 测试在与生产应用程序不同的进程中运行.这意味着您无法从测试套件访问任何生产类.

UI Tests run in a separate process from your production app. This means that you cannot access any production classes from your test suite.

除了触摸屏幕之外,UI 测试的唯一交互是设置启动参数或修改启动环境.

The only interaction UI Tests have, outside of touching the screen, is by setting launch arguments or modifying the launch environment.

您可以使用其中任何一个来在应用启动时重置您的应用.例如,在您的 UI 测试测试中:

You can use either of these to reset your app when it launches. For example, in your UI Testing tests:

@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

然后,当您的应用启动时,您可以检查此参数.如果存在,请调用您应用的重置"方法.

Then, when your app launches you can check for this argument. If it exists, call your app's "reset" method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if ([[[NSProcessInfo processInfo] arguments] containsObject:@"UI-TESTING"]) {
        [[CertificateManager sharedInstance] resetApplication];
    }

    return YES;
}

这篇关于XCode7 UITesting - 如何添加可从 UITestCase 使用的主要目标类(未定义符号错误)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆