<a href="https://swiftlang.cn/package-manager">
<img src="https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat" alt="Swift Package Manager" />
</a>
<a href="https://twitter.com/unsignedints">
<img src="https://img.shields.io/badge/[email protected]?style=flat" alt="Twitter: @unsignedints" />
</a>
围绕XCTestTestCase的一个包装器,使使用XCTestExpectations更加简洁
概览
将它
let exp = expectation(description: #function)
AsyncTask {
exp.fulfill()
}
waitForExpectations(timeout: 5)
变为这样
expect { expectation in
AsyncTask {
expectation.fulfill()
}
}
这可能看起来改进不大,但它允许在不显式声明一个XCTestExpectation实例的情况下编写异步单元测试,并且无需声明等待多长时间。
方法的默认签名将期望的名称设置为#function
以提高清晰度,超时设置为5秒。这两个都可以覆盖
expect("Test Name", limitingTo: 3.0) { expectation in
// Perform async task
}