Swift IOS-测试警报UialertController
我想在警报上进行一些测试,UialertController。这就是测试的样子:
class TransactionsListViewControllerTests: XCTestCase {
private var viewController: MockTransactionsListViewController!
func testPresentAlertForAccountInCollection() throws {
let fetchAlertContent = try retrieveAlertContent(mockPath: "alertContent.json", refresh: false)
if let error = fetchAlertContent.result?.error {
XCTFail(error.localizedDescription)
return
}
let alertController = UIAlertController(
title: fetchAlertContent.title,
message: fetchAlertContent.description, preferredStyle: .alert
)
let okButton = UIAlertAction(title: fetchAlertContent.buttonTitle, style: .default)
alertController.addAction(okButton)
viewController.present(alertController, animated: false, completion: nil)
let expectation = XCTestExpectation(description: "show alert")
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
XCTAssertTrue(self.viewController.presentedViewController is UIAlertController)
expectation.fulfill()
}
}
}
如何正确测试所呈现的视图的uialertController的正确方法?该测试在我的本地存储库上正常工作,但是当该测试在我们的工作领域(TeamCity)上时,它面临一些问题并在同一模块中引用另一个测试。
XCTASSERTTRUE似乎正在同一模块中测试另一个快照测试,并且我在GitHub/TeamCity上遇到了问题,说XCTASSERTTRUE在另一个测试文件中失败了。我想知道如何改进此测试,以便它在此文件中引用。希望这有意义,可以提供更多的澄清
I'd like to do some testing on an Alert, UIAlertController. This is what the testing looks like:
class TransactionsListViewControllerTests: XCTestCase {
private var viewController: MockTransactionsListViewController!
func testPresentAlertForAccountInCollection() throws {
let fetchAlertContent = try retrieveAlertContent(mockPath: "alertContent.json", refresh: false)
if let error = fetchAlertContent.result?.error {
XCTFail(error.localizedDescription)
return
}
let alertController = UIAlertController(
title: fetchAlertContent.title,
message: fetchAlertContent.description, preferredStyle: .alert
)
let okButton = UIAlertAction(title: fetchAlertContent.buttonTitle, style: .default)
alertController.addAction(okButton)
viewController.present(alertController, animated: false, completion: nil)
let expectation = XCTestExpectation(description: "show alert")
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
XCTAssertTrue(self.viewController.presentedViewController is UIAlertController)
expectation.fulfill()
}
}
}
What would be the correct way to test that the UIAlertController that is the presented view? The test works fine on my local repository, but when this test is on our work domain (TeamCity), it's facing some issues and referencing another Test in the same module.
The XCTAssertTrue appears to be testing another SnapShot test within the same module and I'm getting issues on GitHub/TeamCity saying that XCTAssertTrue failed with a different test file. I'd like to know how I can improve this testing so that it reference within this file. Hopefully that makes sense, can provide more clarification
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论