<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTAssertEqual(_:_:_:file:line:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "s:6XCTest14XCTAssertEqual___4file4lineyxyKXK_xyKXKSSyXKs12StaticStringVSutSQRzlF"
  },
  "title" : "XCTAssertEqual(_:_:_:file:line:)"
}
-->

# XCTAssertEqual(_:_:_:file:line:)

Asserts that two values are equal.

```
func XCTAssertEqual<T>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) where T : Equatable
```

## Parameters

`expression1`

An expression of type `T`, where `T` is `Equatable`.

`expression2`

A second expression of type `T`, where `T` is `Equatable`.

`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

```objc
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)`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)