---
title: "XCTExpectFailure(_:enabled:strict:failingBlock:issueMatcher:)"
framework: xctest
role: symbol
role_heading: Function
path: "xctest/xctexpectfailure(_:enabled:strict:failingblock:issuematcher:)"
---

# XCTExpectFailure(_:enabled:strict:failingBlock:issueMatcher:)

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

## Declaration

```swift
func XCTExpectFailure<R>(_ failureReason: String? = nil, enabled: Bool? = nil, strict: Bool? = nil, failingBlock: () throws -> R, issueMatcher: ((XCTIssue) -> Bool)? = nil) rethrows -> R
```

## Parameters

- `failureReason`: An optional string that describes why the test expects a failure.
- `enabled`: A Boolean value that indicates whether the test checks for the expected failure.
- `strict`: A Boolean value that indicates whether the test reports an error if the expected failure doesn’t occur.
- `failingBlock`: A block of test code and assertions where the test expects a failure.
- `issueMatcher`: A block of code that determines whether the test issue fulfills the expected 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(_:options:failingBlock:)](xctest/xctexpectfailure(_:options:failingblock:).md)
