【问题标题】:xctest using NSPredicate to replace eventually of Quick/Nimblexctest 使用 NSPredicate 最终替换 Quick/Nimble
【发布时间】:2017-03-13 23:51:50
【问题描述】:

我正在尝试将下面的测试用例从 quick/nimble 转换为 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")
      }
    }

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

【问题讨论】:

  • guidValue 和 appGuid 是同一类型吗?
  • 是的,它们是同一类型

标签: swift nspredicate xctest


【解决方案1】:

这行得通:

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")
      }
    }

【讨论】:

  • 使用 == 而不是 MATCHES,因为 MATCHES if 用于正则表达式
猜你喜欢
  • 2015-03-28
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多