<!--
{
  "availability" : [
    "Xcode: 16.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Trait/enabled(if:_:sourceLocation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift Testing",
      "Testing"
    ],
    "preciseIdentifier" : "s:7Testing5TraitPA2A09ConditionB0VRszrlE7enabled2if_14sourceLocationAESbyYbKXA_AA7CommentVSgAA06SourceG0VtFZ"
  },
  "title" : "enabled(if:_:sourceLocation:)"
}
-->

# enabled(if:_:sourceLocation:)

Constructs a condition trait that disables a test if it returns `false`.

```
static func enabled(if condition: @autoclosure @escaping @Sendable () throws -> Bool, _ comment: Comment? = nil, sourceLocation: SourceLocation = #_sourceLocation) -> Self
```

## Parameters

`condition`

A closure that contains the trait’s custom condition logic.
If this closure returns `true`, the trait allows the test to run.
Otherwise, the testing library skips the test.

`comment`

An optional comment that describes this trait.

`sourceLocation`

The source location of the trait.

## Return Value

An instance of [`ConditionTrait`](/documentation/Testing/ConditionTrait) that evaluates the
closure you provide.

## Discussion

---

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)