<!--
{
  "availability" : [
    "*: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestRun/recordFailure(withDescription:inFile:atLine:expected:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestRun(im)recordFailureWithDescription:inFile:atLine:expected:"
  },
  "title" : "recordFailure(withDescription:inFile:atLine:expected:)"
}
-->

# recordFailure(withDescription:inFile:atLine:expected:)

Records a failure during test execution for the test run.

```
func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: Int, expected: Bool)
```

## Parameters

`description`

The description of the failure.

`filePath`

The file path to the source file where the failure occurred or `nil` if unknown.

`lineNumber`

The line number in the source file at `filePath` where the failure occurred.

`expected`

<doc://com.apple.documentation/documentation/Swift/true> if the failure was the result of a failed assertion, <doc://com.apple.documentation/documentation/Swift/false> if it was the result of an uncaught exception.

## Discussion

Don’t call this method before the test run starts or after it stops.

---

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)