<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/expectation(description:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestCase(im)expectationWithDescription:"
  },
  "title" : "expectation(description:)"
}
-->

# expectation(description:)

Creates a new expectation with an associated description.

```
func expectation(description: String) -> XCTestExpectation
```

## Parameters

`description`

A string to display in the test log for this expectation, to help diagnose failures.

## Discussion

Use this method to create [`XCTestExpectation`](/documentation/XCTest/XCTestExpectation) instances that can be fulfilled when asynchronous tasks in your tests complete.

To fulfill an expectation that was created with [`expectation(description:)`](/documentation/XCTest/XCTestCase/expectation(description:)), call the expectation’s [`fulfill()`](/documentation/XCTest/XCTestExpectation/fulfill()) method when the asynchronous task in your test has completed.

---

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)