ios - 如何在 Swift 中编写 UI 测试来测试点击按钮时标签是否可见?

标签 ios swift ui-testing

我在 Swift 和 UI/单元测试方面都是初学者。

目标是测试点击 View 时标签是否可见。是的,一个观点。 问题是我的“按钮”是一个 UIView 类,而我的标签是这个 UIView 类内部的 @IBInspectable 计算属性。所以,我对我的测试方式感到有点困惑。

如果我能在哪里找到有关 UI/单元测试的一般解释,我将不胜感激。 :)谢谢!

最佳答案

您好,您需要测试点击右侧按钮时调用的函数。

我假设您不仅仅使用 Swift。

所以一些基本步骤可以是

  1. 在模拟按钮点击之前检查测试用例类中按钮的可见性。
  2. 要模拟按钮点击,您可以调用 button.sendActions(for: .touchUpInside)
  3. 现在检查按钮的可见性。 在这里您可以简单地使用 XCAssertTrue 和 XCAssertFalse 来检查按钮可见性

一些有用的链接 -

https://useyourloaf.com/blog/ui-testing-quick-guide/

https://www.raywenderlich.com/960290-ios-unit-testing-and-ui-testing-tutorial

关于ios - 如何在 Swift 中编写 UI 测试来测试点击按钮时标签是否可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59895893/

相关文章:

ios - 使用 Swift 使用键盘向上移动 TextView

ios - 更改 UILabel 中某个单词的颜色

iphone - 如何将 UIView 移到其 SuperView 之外?

swift - 在 Swift 中返回实例类型

testing - MonkeyTalk bool 逻辑

android - Espresso : "Unresolved reference: atPosition"

ios - 如何通过 VPN 连接发送所有流量?

arrays - Swift 中的 elementsEqual 和 '==' 有什么区别?

swift - 为什么调用 removeAtIndex : on a string invert the result if called within a string literal?

android - Espresso : How to do custom swipe e. 克。 swipeTop 或 swipeBottom