class - UITests 助手类中的扩展与类
问题描述
我想为我的 UI 测试编写助手类。
A.swift(测试用例类)
class A:XCTestCase {
//contains test cases, setUp() & tearDown()
...
}
B.swift(助手类)
方法一:
class B:XCTestCase {
//only helper functions, no setUp, no tearDown and no test cases
func sampleHelper() {
...
}
...
}
B().sampleHelper()
将调用 sampleHelper 函数(在A中使用时)
方法二:
extension XCTestCase {
//only helper functions, no setUp, no tearDown and no test cases
func sampleHelper() {
...
}
...
}
sampleHelper()
将调用辅助函数(在A中使用时)
问题:
编写辅助类的最佳方法是什么?我知道扩展是静态的,但如果代码库很大,它真的会影响内存/性能吗?
解决方案
If you want to add only some custom methods to XCTestCase it is better and more clear to use method #2 and place the whole extension to separate file/folder somewhere near the place you want to use your custom methods
On the other hand, you should not use method #2 if you want to override methods of XCTestCase as it is violation of the language directive. More details you can read in Apple Developer Guide and in here.
推荐阅读
- android - 使用 Quick Tile、Android Studio 启动 Activity
- sql - CLOB 数据类型可以存储为 VARCHAR2
- amazon-web-services - 如何从 vars 文件中读取 terraform 列表
- c - GDB 向局部变量显示错误的地址
- java - 我正在为 android 使用 Firebase Apple 登录
- php - 当从 excel 文件中插入日期到 MySQL 数据库中时,我遇到了日期更改问题
- amazon-web-services - Amazon Athena 如何从 S3 中选择新文件/记录
- python - 使用 Anaconda 安装包失败
- vim - 如何更改 vim 命令执行优先级?
- bdd - 在空手道中使用 If 条件提取值