XCTAssertEqual(_:_:_:file:line:)
Asserts that two values are equal.
Declaration
func XCTAssertEqual<T>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) where T : EquatableParameters
- expression1:
An expression of type
T, whereTisEquatable. - expression2:
A second expression of type
T, whereTisEquatable. - message:
An optional description of a failure.
- file:
The file where the failure occurs. The default is the filename of the test case where you call this function.
- line:
The line number where the failure occurs. The default is the line number where you call this function.
Discussion
Use this function to compare two non-optional values of the same type.
Listing 1. Comparing Non-Optional Values Of The Same Type
class FrameSizeTests: XCTestCase {
func testInitialFrameSize() {
let view = CustomView()
let expectedSize = CGSize(width: 640.0, height: 480.0)
XCTAssertEqual(view.frame.size, expectedSize, "Unexpected frame size.")
}
}Listing 1 creates a new instance of a custom class called CustomView, and checks that its size is equal to CGSize(width: 640.0, height: 480.0).