swift - 属性字符串的 Swift 单元测试
问题描述
我想为属性字符串创建一个单元测试。这是我的代码
func setupMyLabel() {
myLabel.isHidden = false
let attributes = [NSAttributedString.Key.font: Style.FontBook.bold,
NSAttributedString.Key.foregroundColor: Theme.brand]
if userConnected {
myLabel.attributedText = NSAttributedString(string: "myLabel_longText".localized, attributes: nil)
.replacingFields(["1": (replacement: "myLabel_firstPart".localized,
attributes: attributes)])
} else {
myLabel.text = NSLocalizedString("myLabel_shortext", comment: "myLabel_shortext")
}
}
这是我编写的单元测试,用于在用户未连接时进行测试,因为标签仅包含文本
import Nimble
import Quick
import Mockingjay
context("When user is not connected"){
it("should display my label, and label should contain shortText string"){
disconnectUser()
vc.setupMyLabel()
expect(vc.myLabel.isHidden).to(beFalse())
expect(vc.myLabel.text).to(equal(String.localizedStringWithFormat("myLabel_shortext".localized, "")))
}
}
但是当用户连接时,我有点坚持为属性编写单元测试!
context("When user is connected"){
it("should display my label, and label should contain longText string"){
connectUser()
vc.setupMyLabel()
expect(vc.myLabel.isHidden).to(beFalse())
expect(vc.myLabel.attributedText).to(equal( .... ?? ))
}
}
解决方案
推荐阅读
- flutter - 如何在颤振中实现这种类型的自定义标签设计?
- r - 将非英语数据从 SQL Server 导入到 R
- mysql - MySQL - 如何按名称排序,然后按字母数字有选择地在表上?
- javascript - 正则表达式 - 或 _ 在字符串的开头或结尾
- python - AWS 更新项目错误 - UpdateItem 操作:提供的关键元素与架构不匹配
- sapui5 - DPC 类被触发两次
- java - Acitvemq 连接到 RHEL7.6 机器超时
- c# - 如何在通用存储库模式 Mvc.Net 实体框架中实现级联下拉列表?
- oracle - oracle数据库中如何压缩所有表
- laravel - 在 laravel 中自定义“can”函数