gpt4 book ai didi

ios - 如何从我的 UI 测试访问我的 swift 类?

转载 作者:搜寻专家 更新时间:2023-11-01 05:45:45 24 4
gpt4 key购买 nike

我有一个像这样的 UI 测试:

    func testHome(){
if(isRedOrange.clear()){
//code
}
}

如何从我的 UI 测试的 isRedOrange.swift 文件访问我的 isRedOrange.clear 函数?

最佳答案

UI 测试是黑盒的,因此您无法访问您的代码

您可以在单元测试中使用@testable import,因此将提供完全访问权限。当您运行 UITests 时,这是行不通的,因为在 UITest 期间,您的测试类无法访问您应用的代码。

来自 Apple 的文档:

UI testing differs from unit testing in fundamental ways. Unit testing enables you to work within your app's scope and allows you to exercise functions and methods with full access to your app's variables and state. UI testing exercises your app's UI in the same way that users do without access to your app's internal methods, functions, and variables. This enables your tests to see the app the same way a user does, exposing UI problems that users encounter.

您必须在元素上使用 .tap() 来实现一切。 .accessibilityIdentifier 将帮助您获得正确的元素

关于ios - 如何从我的 UI 测试访问我的 swift 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51799940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com