<!--
{
  "availability" : [

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

# XCTExpectFailure(_:options:)

Instructs the test to expect a failure in an upcoming assertion, with options to customize expected failure checking and handling.

```
func XCTExpectFailure(_ failureReason: String? = nil, options: XCTExpectedFailure.Options = .init())
```

## Parameters

`failureReason`

An optional string that describes why the test expects a failure.

`options`

Options that determine how the test matches the expected failure to an actual test failure, and whether an unfulfilled expected failure results in a test failure.

---

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)