【问题标题】:XCTest .xib of custom UIView in SwiftSwift 中自定义 UIView 的 XCTest .xib
【发布时间】:2018-06-15 09:38:43
【问题描述】:

你如何 XCTest 一个 .xib 谁的类设置为 UIView 类型的自定义类?

我想对此进行单元测试,并认为我需要从 nib 实例化视图(完整的 IBOutlets),然后测试如下内容:tempSearchCardView.titleLabel.text == "Hello World"

我试过tempSearchCardView = Bundle.main.loadNibNamed("SearchCardView", owner: nil, options: nil)![0] as? SearchCardViewtempSearchCardView = nil

...

这是我的 IB 情况:

...

这是我的 .swift 文件:

【问题讨论】:

    标签: ios swift uiview xib xctest


    【解决方案1】:

    我在这里找到了答案:Swift 2.0: Could not cast value MyApp.MyCustomClass to MyAppTests.MyCustomClass when using Set

    我尝试了我能找到的大多数其他教程/建议。

    上面的帖子说要从测试目标中删除文件,然后@testable import MyApp ...然后testSearchCardView = Bundle.main.loadNibNamed("SearchCardView", owner: self, options: nil)?.first as! SearchCardView按预期工作!!!

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 2017-10-01
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多