XCTAssertEqualObjects 的替代品是什么? [英] What is the replacement for XCTAssertEqualObjects?

查看:40
本文介绍了XCTAssertEqualObjects 的替代品是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定确切时间,但至少从 Xcode 7.2 开始,XCTAssertEqualObjects 不再可用.

Not sure exactly when but at least as of Xcode 7.2, XCTAssertEqualObjects is no longer available.

有没有无需求助的替代品?

Is there a replacement for this without having to resort to?

   XCTAssertTrue(foo == bar)

请注意 Apple 的 "Writing Test Classes and Methods" 似乎已经过时,仍然指的是缺失的课程.

Note that Apple's "Writing Test Classes and Methods" appears out of date and still refers to the missing class.

推荐答案

我会更具体地说明您正在测试的内容.

I would be a bit more specific about what you are testing.

平等和身份不是一回事,尤其是在 Swift 中,那里有更丰富的值类型.

Equality and identity are not the same thing, especially in Swift where there are far richer value types.

如果您想测试符合 Equatable 所定义的相等性,请使用:

If you want to test equality as defined by conformance to Equatable then use:

XCTAssertTrue(a == b)

如果要测试两个引用类型是否相等:

If you want to test that two reference types are equal:

XCTAssertTrue(a === b)

我觉得这样更好,因为断言更明确;对象是相等还是相同.

I feel this is better because the assertion is more explicit; are the objects equal or identical.

记住关于 Swift 中的值类型的 WWDC15 会议 - 它建议始终使您的值类型符合 Equatable.

Remember the WWDC15 session on Value Types in Swift - which recommends always making your value types conform to Equatable.

这篇关于XCTAssertEqualObjects 的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆