swift - xctest 使用 NSPredicate 最终取代 Quick/Nimble

标签 swift nspredicate xctest

我正在尝试将以下测试用例从快速/灵活转换为 xctest:

expect(foundation.appGuid).toEventually(equal(guidValue))

下面是我正在使用的代码,但测试崩溃了:

let successPredicate = NSPredicate(format: "SELF MATCHES %@", guidValue)
    expectation(for: successPredicate, evaluatedWith: foundation.appGuid) {
      return foundation.appGuid == guidValue
    }

    waitForExpectations(timeout: 5) { (error) -> Void in
      if error != nil {
        XCTFail("foundation.appGuid NOT Equal to guidValue")
      }
    }

我在上面的代码中做错了什么吗?

最佳答案

这有效:

let successPredicate = NSPredicate(format:  "SELF == %@", self.guidValue)
    expectation(for: successPredicate, evaluatedWith: foundation.serviceConfig.appGuid) {
      return foundation.serviceConfig.appGuid == self.guidValue
    }

    waitForExpectations(timeout: 5) { (error) -> Void in
      if error != nil {
        XCTFail("foundation.serviceConfig.appGuid NOT Equal to guidValue")
      }
    }

关于swift - xctest 使用 NSPredicate 最终取代 Quick/Nimble,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42775496/

相关文章:

Xcode Workspace 中的 iOS 框架测试失败

swift - 将 url 从标记传递到 Controller

ios - Apple - 如果密码更改,我们如何在 iOS 应用程序中使用 Touch ID

swift - Swift 中 NSFetchRequest 的多个 NSPredicates?

ios - XCTest - 如何使用 Command 和 Shift 创建多个键修饰符标志?

macos - 如何使用 XCTest 对基于文档的应用程序进行 UI 测试?

iOS RxSwift - 如何将 “disconnect” 设为可观察对象?

ios - 快速子类化 SKSpriteNode 访问错误

ios - 带有iOS 10.3的iPhone 5和iPad第四代在NSPredicate崩溃

cocoa - NSPredicate with boolean 并不是将 bool 值与 NO 进行比较