我刚刚开始深入研究新的 Swift 测试框架,但遇到了特征方面的问题.enabled(if: Bool)
。
下面我的代码返回Instance member 'accessTokenIsNil' cannot be used on type 'AuthorizationTests'; did you mean to use a value of this type instead?
部分错误.enabled(if: accessTokenIsNil())
。
import Testing
@testable import mews
import SwiftUI
struct AuthorizationTests {
let accessTokenManager = AccessTokenManager()
func accessTokenIsNil() -> Bool {
accessTokenManager.token == nil
}
@Test("Get initial access token", .enabled(if: accessTokenIsNil()))
func getAccessTokenSucces() {
// continue test
}
}
下面是来自Apple 的官方文档,所以我不确定我做错了什么。
func allIngredientsAvailable(for food: Food) -> Bool { ... }
@Test(
"Can make sundaes",
.enabled(if: Season.current == .summer),
.enabled(if: allIngredientsAvailable(for: .sundae))
)
func makeSundae() async throws { ... }