---
title: "timeLimit(_:)"
framework: testing
role: symbol
role_heading: Type Method
path: "testing/trait/timelimit(_:)"
---

# timeLimit(_:)

Construct a time limit trait that causes a test to time out if it runs for too long.

## Declaration

```swift
static func timeLimit(_ timeLimit: TimeLimitTrait.Duration) -> Self
```

## Parameters

- `timeLimit`: The maximum amount of time the test may run for.

## Mentioned in

Limiting the running time of tests

## Return Value

Return Value An instance of TimeLimitTrait.

## Discussion

Discussion Test timeouts do not support high-precision, arbitrarily short durations due to variability in testing environments. You express the duration in minutes, with a minimum duration of one minute. When you associate this trait with a test, that test must complete within a time limit of, at most, timeLimit. If the test runs longer, the testing library records a Issue.Kind.timeLimitExceeded(timeLimitComponents:) issue, which it treats as a test failure. The testing library can use a shorter time limit than that specified by timeLimit if you configure it to enforce a maximum per-test limit. When you configure a maximum per-test limit, the time limit of the test this trait is applied to is the shorter of timeLimit and the maximum per-test limit. For information on configuring maximum per-test limits, consult the documentation for the tool you use to run your tests. If a test is parameterized, this time limit is applied to each of its test cases individually. If a test has more than one time limit associated with it, the testing library uses the shortest time limit. If you apply this trait to a test suite, then it sets the time limit for each test in the suite, or each test case in parameterized tests in the suite. For example, if a suite contains five tests and you apply a time limit trait with a duration of one minute, then each test in the suite may run for up to one minute.

## See Also

### Customizing runtime behaviors

- [Enabling and disabling tests](testing/enablinganddisabling.md)
- [Limiting the running time of tests](testing/limitingexecutiontime.md)
- [enabled(if:_:sourceLocation:)](testing/trait/enabled(if:_:sourcelocation:).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)
