UI 测试期间的测试对象状态 (iOS)

Test object state during UI testing (iOS)

是否可以在UI测试期间测试对象状态(全局变量,单例对象)?例如,我有 UI 测试点击某些按钮并将文本输入到文本字段的位置。我想断言对象状态会根据用户输入正确更改。

在 UI 测试期间,您将无法从应用程序代码访问变量。您的应用和 UI 在单独的可执行文件中测试 运行,并且在 运行 时无法访问彼此的内部。

要检查文本字段的状态,您需要从表示文本字段的 XCUI元素中读取状态(如果您感兴趣的状态在 UI) 或者写一个单元测试来检查状态。

来自 Apple(通过 ):

UI tests execute differently from Unit tests - Unit tests run inside your application process so they can access your application code. UI tests execute in a separate process, outside your application, so they can simulate how the user interacts with the application. It’s not expected that you will be able to access your app class from a UI test.