<!--
{
  "availability" : [

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

# XCTExpectFailure(_:options:failingBlock:)

Instructs the test to expect a failure in an assertion in the provided block of code, with options to customize expected failure checking and handling.

```
func XCTExpectFailure<R>(_ failureReason: String? = nil, options: XCTExpectedFailure.Options = .init(), failingBlock: () throws -> R) rethrows -> R
```

## 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.

`failingBlock`

A block of test code and assertions where the test expects a failure.

## Return Value

If the `failingBlock` you provide returns a value or throws an error, the function returns that value or rethrows the error.

---

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)