---
title: "XCTExpectFailure(_:options:failingBlock:)"
framework: xctest
role: symbol
role_heading: Function
path: "xctest/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.

## Declaration

```swift
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

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

## See Also

### Expected Failures

- [XCTExpectedFailure](xctest/xctexpectedfailure.md)
- [XCTExpectedFailure.Options](xctest/xctexpectedfailure/options.md)
- [XCTExpectFailure(_:options:)](xctest/xctexpectfailure(_:options:).md)
- [XCTExpectFailure(_:enabled:strict:issueMatcher:)](xctest/xctexpectfailure(_:enabled:strict:issuematcher:).md)
- [XCTExpectFailure(_:enabled:strict:failingBlock:issueMatcher:)](xctest/xctexpectfailure(_:enabled:strict:failingblock:issuematcher:).md)
