如何从我的UI测试访问我的swift类? [英] How do I access my swift classes from my UI tests?

查看:82
本文介绍了如何从我的UI测试访问我的swift类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的UI测试:

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

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

How would I access my isRedOrange.clear function from my isRedOrange.swift file from my UI tests?

推荐答案

UI测试被黑框显示,因此您无权访问您的代码.

UI Tests are black boxed, so you cant have access to your code.

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

You can use @testable import in Unit Tests, so full access will be provided. When you're running UITests this is not working, because during a UITest your test class cannot access your app's code.

来自Apple的文档:

From Apple's Docs:

UI测试在根本上不同于单元测试.单元测试使您可以在应用程序范围内工作,并可以进行锻炼函数和方法,可以完全访问应用程序的变量和状态.用户界面测试以与用户相同的方式锻炼应用的用户界面无需访问应用程序的内部方法,函数和变量.这使您的测试可以以与用户相同的方式查看应用这样做,暴露出用户遇到的UI问题.

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()的on元素来实现所有目的. .accessibilityIdentifier 将帮助您获取正确的元素

You must achieve everything using .tap()'s on elements. .accessibilityIdentifier will help you to get the right element

这篇关于如何从我的UI测试访问我的swift类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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