旋转测试通知中心

问题描述 投票:0回答:1
在xctest中,我可以使用

expectation(forNotification:)

测试NSNOTIFICAYCENTER通知:

func testLoginNotification() { let notificationExpectation = expectation(forNotification: .login, object: nil, handler: nil) methodPostNotificationLogin() wait(for: [notificationExpectation], timeout: 2) }
如何在迅速测试中执行此操作?

@Test fun loginNotification() { #expect() }

	
swift unit-testing swift-testing
1个回答
0
投票
您需要测试的是,您的代码说正确的内容to notificationcenter _,这是通过嘲笑通知中心,您可以轻松地进行Swift测试。您可能还需要测试当您的通知

arrives

时,您的代码会做什么,而这也是您可以通过嘲笑通知中心来轻松地进行快速测试的事情。

如果在单位测试期间触发了real通知中心,则是一个主要的错误,需要修复。换句话说,这里的通知中心就像网络一样(您也绝不应该测试网络)。测试仅测试系统,即您的代码。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.