X code 7:是应用测试和UI测试之间不可逾越的鸿沟? [英] Xcode 7: is chasm between app tests and UI tests unbridgeable?

查看:227
本文介绍了X code 7:是应用测试和UI测试之间不可逾越的鸿沟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

X code 7†有一个新的方式来直接测试你的用户界面,其中包括一个新的测试目标的iOS UI测试包(或OS X)。

Xcode 7† has a new way to test your UI directly, including a new testing target "iOS UI Testing Bundle" (or "OS X").

在UI测试的目标,似乎没有内置的访问模型或包括你的App类。例如。 [UIApplication的sharedApplication] 不会从你的UI测试调用。
这意味着,应用测试和UI测试跨越可能不可逾越的鸿沟存在。

In the UI testing target, it appears there's no built-in access to the model or classes that comprise your App. E.g. [UIApplication sharedApplication] would not be callable from your UI tests. This implies that "app tests" and "UI tests" exist across a possibly unbridgeable chasm.

如前所述这里

问题是,X code'S UI测试不允许进入实际应用。

The problem is that Xcode’s UI testing does not allow access to the actual app.

问题:


  1. 可以这样鸿沟弥合?如果是这样,如何​​在细节,在GitHub上构建和连接器设置以及可能的工作 X codeproj

  2. 其中,可能这一鸿沟的一个明确的说法被发现,苹果中的文档。

†在写这篇文章的时候,测试版软件。


† At the time of writing, beta software.

推荐答案

黑盒测试

UI测试是一个黑盒测试框架。你不应该知道关于code你正在测试的具体实现。

UI Testing is a black-box testing framework. You shouldn't have to know anything about the implementation of the code you are testing.

例如,你应该只关心上的标签的值发生变化,而不是控制器传递正确的数据给视图。您可以从您的应用程序的的角度来看的用户认为UI测试。她不在乎你怎么 ItemsViewController 工作(甚至它的存在),那么为什么要UI测试?

For example, you should only care that the value on a label changes, not that the controller passed the right data to the view. You can think of UI Testing from the user of your app's perspective. She doesn't care how your ItemsViewController works (or even that it exists), so why should the UI Tests?

得到它的工作

话虽这么说,我理解你的无奈。这将是巨大的,如果你能旋转了一个视图控制器,然后点击周围的UI测试和作出断言。然而,随着测试5的,这是不可能的。

That being said, I understand your frustration. It would be great if you could spin up a view controller and then tap around with UI Testing and making assertions. However, as of Beta 5 this is not possible.

有趣的是,你可以,但是,创建应用程序的对象的实例,在您的UI测试的顶部有一个简单的 @testable进口模块名。请注意,你不能真正用它通过 .tap()式的方法进行互动,因为它是一个 UI * 类,而不是一个 XCUI * 之一。

What's interesting is that you can, however, create instances of your app's objects with a simple @testable import ModuleName at the top of your UI Tests. Note that you can't actually interact with it via the .tap()-like methods, as it's a UI* class, not a XCUI* one.

考虑甜甜圈是应用程序的模块名称。

Consider Donut to be the application's module name.

import XCTest
@testable import Donut

class DonutUITests: XCTestCase {
    let app = XCUIApplication()

    override func setUp() {
        continueAfterFailure = false
        app.launch()
    }

    func testItemsViewController() {
        let controller = ItemsViewController()
        controller.addItemButton.tap() // <---- UIButton does not respond to tap()!
    }
}

这篇关于X code 7:是应用测试和UI测试之间不可逾越的鸿沟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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