---
title: "enabled(if:_:sourceLocation:)"
framework: testing
role: symbol
role_heading: Type Method
path: "testing/trait/enabled(if:_:sourcelocation:)"
---

# enabled(if:_:sourceLocation:)

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

## Declaration

```swift
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.

## Mentioned in

Enabling and disabling tests

## Return Value

Return Value An instance of ConditionTrait that evaluates the closure you provide.

## See Also

### Customizing runtime behaviors

- [Enabling and disabling tests](testing/enablinganddisabling.md)
- [Limiting the running time of tests](testing/limitingexecutiontime.md)
- [enabled(_:sourceLocation:_:)](testing/trait/enabled(_:sourcelocation:_:).md)
- [disabled(_:sourceLocation:)](testing/trait/disabled(_:sourcelocation:).md)
- [disabled(if:_:sourceLocation:)](testing/trait/disabled(if:_:sourcelocation:).md)
- [disabled(_:sourceLocation:_:)](testing/trait/disabled(_:sourcelocation:_:).md)
- [timeLimit(_:)](testing/trait/timelimit(_:).md)
