如何修改从 XCTest 中的 .xcassets 加载的动态 UIColor 的当前 traitCollection?

问题描述

我想使用从 .xcassets 文件加载的动态颜色运行单元测试。这些颜色有浅色和深色的外观。对于我的测试,我需要读取明暗值的 RGB 值。我总是只能看到光模式版本。这是有道理的,因为调试器总是向我展示这个 traitCollection:

我如何为这个测试修改它?如何将 UserInterfaceStyle 设置为 Dark? (这是常规 XCTest - 不是 XCUITest。)

这是实际测试:

func compare(_ color1: UIColor,_ name: String) {
    let color2 = UIColor(named: name)!
    XCTAssert(color1.cgColor == color2.cgColor)
}

5 年前的一个类似问题只建议 XCUITest 作为唯一的选择:How to test right-to-left language in iOS XCTest unit tests? 但这是在 traitCollections 出现之前,对吧?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)