UIScreen 边界在 Snapshop 测试中不正确

问题描述 投票:0回答:0

我正在尝试使用 swift-snapshot-testing 进行快照测试。它在大多数情况下都能找到,但我有一个大问题。 例如这是我的测试

func test_onboarding_iPhone13() {
    let vc = OnboardingViewController()
    assertSnapshot(matching: vc, as: .image(on: .iPhone13(.portrait)), record: true)
}

所以它应该在 iPhone 13 上运行测试,并且在那个

vc
上我使用
UIScreen.main.bounds
来计算一些尺寸,并且在测试不运行时运行良好,但在 snapshop 测试中,
UIScreen.main.bounds
的值将等于

(lldb) p UIScreen.main.bounds
(CGRect) $R0 = (origin = (x = 0, y = 0), size = (width = 320, height = 480))

哪一个完全不正确,我做错了吗?任何人有同样的经历?谢谢

swift xcode-ui-testing gui-testing
© www.soinside.com 2019 - 2024. All rights reserved.