<!--
{
  "availability" : [

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

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

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

```
func XCTExpectFailure(_ failureReason: String? = nil, enabled: Bool? = nil, strict: Bool? = nil, issueMatcher: ((XCTIssue) -> Bool)? = nil)
```

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

`issueMatcher`

A block of code that determines whether the test issue fulfills the expected 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)