带可选的XCTAssertEqual(不等于)

时间:2015-01-07 08:30:40

标签: unit-testing swift

我想在断言中做出以下结论:

XCTAssertEqual(sut.dataSource?.delegate, userInterface, "Data source's delegate should be the user interface")

属性dataSourcedelegate是选项。我尝试用let作业打开它们,但它基本上归结为

Generic parameter 'T' cannot be bound to non-@objc protocol type 'FetchedResultsControllerDataSourceDelegate'

Type 'FetchedResultsControllerDataSourceDelegate?' does not conform to protocol 'Equatable'

如何断言是否正确设置了可选关系?

1 个答案:

答案 0 :(得分:3)

问题在于“等于”比较值。 NSFetchedResultsControllerDataSourceDelegate不符合Equatable,因此无法比较其值。您应该将其身份与“与===”运算符相同。

XCTAssertTrue(sut.dataSource?.delegate === userInterface, "Data source's delegate should be the user interface")