断言代码在单元测试中的某个时刻运行?

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

我有这个单元测试:

func testState() {
    searchController.filter.query = "Missouri"
    searchController.resultsSignal.subscribePast(with: self) { sections in

        if sections.count < 1 { return }
        // Want to test that code at least gets to here at some point
        ...
    }
}

而且我想确保我至少在某个时候超越了if sections.count < 1 { return }线。

由于它在触发信号时运行,我不在乎是否有某个点被触发的不同信号,但我确实想确保在测试的某个时刻sections.count> 0。

有没有办法做到这一点?我正在考虑使用布尔值并将其初始化为false,然后如果sections.count多于一个则将其设置为true,并断言该值为true,但这不起作用,除非我因为使用​​信号而延迟。谢谢。

swift unit-testing signals
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.