<!--
{
  "documentType" : "article",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/nil-and-non-nil-assertions",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Nil and Non-Nil Assertions"
}
-->

# Nil and Non-Nil Assertions

Check whether a test condition has, or doesn’t have, a value.

## Topics

### Tests for a Nil Condition

[`XCTAssertNil(_:_:file:line:)`](/documentation/XCTest/XCTAssertNil(_:_:file:line:))

Asserts that an expression is `nil`.

[`XCTAssertNil`](/documentation/XCTest/XCTAssertNil)

Asserts that an expression is `nil`.

### Tests for a Non-Nil Condition

[`XCTAssertNotNil(_:_:file:line:)`](/documentation/XCTest/XCTAssertNotNil(_:_:file:line:))

Asserts that an expression is not `nil`.

[`XCTUnwrap(_:_:file:line:)`](/documentation/XCTest/XCTUnwrap(_:_:file:line:))

Asserts that an expression is not `nil,` and returns the unwrapped value.

[`XCTAssertNotNil`](/documentation/XCTest/XCTAssertNotNil)

Asserts that an expression is not `nil`.



---

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)