正如在注释中提到的,您应该期望您的单元测试代码没有完全覆盖;特别是对于
XCTFail
电话。单元测试的全部目标是
.
即使你重组了你的源头
在其他地方,你仍然打算让它永远不会被执行。通过使用
XCTAssertEqual
再一次。
func testUrlRequest_WithAuthenticationNoToken_ExpectingAuthenticationFailure() {
let mockController = MockAuthenticationController()
mockController.token = nil
Server.authenticationController = mockController
var failed = false
do {
_ = try Server.urlRequestWithHeaders(to: arbitraryEndpoint, excludeBearerToken: false)
} catch {
XCTAssertEqual(error as? Server.Errors, .authenticationFailure)
failed = true
}
XCTAssertEqual(failed, true, "Expected throw when no token is present")
}